Rectangle 27 201

Use the Desktop#browse(URI) method. It opens a URI in the user's default browser.

public static void openWebpage(URI uri) {
    Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
        try {
            desktop.browse(uri);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

public static void openWebpage(URL url) {
    try {
        openWebpage(url.toURI());
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}

+1 for me too. Clear and direct.

this doesn't appear to work in JAR files created by Netbeans 7.x. It works when the code is run from Netbeans, but not when deployed as a JAR file... at least in my experience. I'm still looking for a solution.

@MountainX Debug and verify that the desktop is supported and that security implementations aren't restricting you from accessing the desktop instance. If you are running the JAR as an applet, security is the likely culprit.

@Vulcan--I'm not running the JAR as an applet. I'm not aware of any security settings that would prevent this from working. I "worked around" it by calling new ProcessBuilder("x-www-browser", uri.toString());. You would think that if there were security restrictions, the ProcessBuilder call would not work. But it does work. I have no idea why desktop.browse(uri) doesn't work, but I have seen that it doesn't work for a lot of people. I was guessing maybe it's a Netbeans issue, but I don't know.

swing - Open a link in browser with java button? - Stack Overflow

java swing browser hyperlink desktop
Rectangle 27 1358

To open a URL/website you do the following:

String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
Intent.ACTION_VIEW
http
https
if (!url.startsWith("http://") && !url.startsWith("https://")) 	url = "http://" + url;

Encode the Query String If any special characters or spaces. then It will work awesome.For Example : String query="For martin Luther King"; query=URLEncoder.encode(query); String url="en.wikipedia.org/wiki/Special:Search?search="+query; Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(browserIntent);

Hi you solution is good but by this process , it search on google first then redirect to browser. I am using Nexus 4 and see this problem. I hope you will check it.

Funny thing here is that startActivity(i) line could produce ActivityNotFound exception so I go for wrap this line in try/catch block to prevent app crash. This could happen if really no browser app installed on target device (yeah, shoot happens) also it could be that your app was forbidden to start a browser using restrict profiles.

From Android Developer web site: Caution: If there are no apps on the device that can receive the implicit intent, your app will crash when it calls startActivity(). To first verify that an app exists to receive the intent, call resolveActivity() on your Intent object. If the result is non-null, there is at least one app that can handle the intent and it's safe to call startActivity(). If the result is null, you should not use the intent and, if possible, you should disable the feature that invokes the intent.

android - Sending an Intent to browser to open specific URL - Stack Ov...

android android-intent
Rectangle 27 1

Need to see what the sql_download view is doing.

In general, I set the content disposition in the view itself. So my custom AbstractView implemenation would look something like :

response.setHeader("Content-disposition", "attachment; filename="+fileName);
response.setContentType("application/vnd.ms-excel");
OutputStream out = response.getOutputStream();
helperClass.exportDataToExcel(data, out);

The content type is also important, to help your browser choose the correct application to load the document.

You should know that these headers are only a suggestion to a browser, Browsers are free to interpret them in their own way. So you will not be able to force all browsers to show a "Open or Save" dialog.

java - How to get files downloaded from url? (not to open in browser) ...

java jsp spring-mvc download
Rectangle 27 5

Have a look at the purpose of @ResponseBody. Problem is due to @ResponseBody anotation which is showing the content as is. The annotation is used when one wants to pass the content as Ajax response. removing the @ResponseBody will solve the purpose.

@endless What's the actual problem being faced by you?

java - Spring redirect not working, only showing redirect:/url in brow...

java spring spring-mvc redirect
Rectangle 27 50

First, to be able to start your app from link with custom scheme 'myapp' in browser / mail, set intent filter as follows.

<intent-filter> 
  <action android:name="android.intent.action.VIEW"/> 
  <category android:name="android.intent.category.DEFAULT"/> 
  <category android:name="android.intent.category.BROWSABLE"/> 
  <data android:scheme="myapp"/> 
</intent-filter>
Intent intent = getIntent();
// check if this intent is started via custom scheme link
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
  Uri uri = intent.getData();
  // may be some test here with your custom uri
  String var = uri.getQueryParameter("var"); // "str" is set
  String varr = uri.getQueryParameter("varr"); // "string" is set
}

if you use custom scheme to launch your app, one of the problem is that: The WebView in another apps may not understand your custom scheme. This could lead to show 404 page for those browser for the link with custom scheme.

The first example I've seen on here that includes how to get the Uri out again in the activity.. thanks!

Where the code that handles the intent should be coded?

@Proverbio: in the main activity of your app, within the onCreate method

@Proverbio in the onCreate of the activity under which you registered the intent-filter. It's certainly not necessarily the main activity

java - How to register some URL namespace (myapp://app.start/) for acc...

java android browser
Rectangle 27 49

First, to be able to start your app from link with custom scheme 'myapp' in browser / mail, set intent filter as follows.

<intent-filter> 
  <action android:name="android.intent.action.VIEW"/> 
  <category android:name="android.intent.category.DEFAULT"/> 
  <category android:name="android.intent.category.BROWSABLE"/> 
  <data android:scheme="myapp"/> 
</intent-filter>
Intent intent = getIntent();
// check if this intent is started via custom scheme link
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
  Uri uri = intent.getData();
  // may be some test here with your custom uri
  String var = uri.getQueryParameter("var"); // "str" is set
  String varr = uri.getQueryParameter("varr"); // "string" is set
}

if you use custom scheme to launch your app, one of the problem is that: The WebView in another apps may not understand your custom scheme. This could lead to show 404 page for those browser for the link with custom scheme.

The first example I've seen on here that includes how to get the Uri out again in the activity.. thanks!

Where the code that handles the intent should be coded?

@Proverbio: in the main activity of your app, within the onCreate method

@Proverbio in the onCreate of the activity under which you registered the intent-filter. It's certainly not necessarily the main activity

java - How to register some URL namespace (myapp://app.start/) for acc...

java android browser
Rectangle 27 45

You need to follow the standard rules for URIs via the W3C and such, which basically means: do not do this.

Android defines a Uri syntax for describing a generic Intent. There are methods on Intent for converting to and from this representation, such as: http://developer.android.com/reference/android/content/Intent.html#toUri(int)

So the way to do this is to use the normal facilities to describe an in your manifest for the kinds of intents you are going to handle with a particular component, especially defining an action name in your own namespace (com.mycompany.myapp.action.DO_SOMETHING or whatever). You can then make an Intent that matches your component, and use Intent.toUri() to get the URI representation of this. This can be placed in your link, and will then when pressed look for something that handles and and thus find your app. Note to be launched from the browser like this, the component's must handle the BROWSABLE category. (You don't need to have this in the Intent you put in the link, the browser will automatically add this in for you.)

This is a newer feature in the platform, which allows you to direct link intents to only your app so that other applications can not intercept and handle them.

In summary: read the regular documentation on intents and intent filters (such as the NotePad tutorial, though you won't be using content: URIs here, probably just custom actions) and get your app working that way. Then you can make a browser link to launch your app in the same way, provided your intent-filter handles the BROWSABLE category.

At first I thought that you didn't explain how ignoring the standard rules for URIs is bad, but then I found your other answer here.

@hackbod: Like Casebash, I am having problems with your instructions. Given an activity, I dump getIntent().toUri(Intent.URI_INTENT_SCHEME).toString(), paste that in a Web page (commonsware.com/sample), try opening it in a browser on the emulator, and I get choices of opening the page in Browser, Contacts, or Phone, but not my activity. That seems strange, considering that the intent: URI from toUri() has the component clause, so I'm not sure how those other apps can get it. I have the BROWSABLE category on the intent filter. If you have any thoughts, please @ me back. Thanks!

Don't bother trying this method if you want your URIs to reliably work; using intent URIs requires cooperation from the app taking the URI. zxing (Barcode Scanner) doesn't accept them (by deliberate design decision, apparently), so if you want to be able to scan barcodes to talk to your app (or take URI input from any other method you don't completely control), you either need to overload http:// (which requires a user choice between browser and your app) or just go with a custom scheme, which as far as I can tell passes transparently into the system and doesn't get caught up anywhere).

@hackbod can you please point me to w3c documentation which suggests to not implement new URI schemes? I have only found rfc2718 which seems to support that.

@hackbod - It appears this would not work with iOS though. It seems registering a unique scheme is the most cross-platform compatible implementation although I agree with you that it pollutes the namespace... developer.apple.com/library/ios/documentation/iPhone/Conceptual/

java - How to register some URL namespace (myapp://app.start/) for acc...

java android browser
Rectangle 27 45

You need to follow the standard rules for URIs via the W3C and such, which basically means: do not do this.

Android defines a Uri syntax for describing a generic Intent. There are methods on Intent for converting to and from this representation, such as: http://developer.android.com/reference/android/content/Intent.html#toUri(int)

So the way to do this is to use the normal facilities to describe an in your manifest for the kinds of intents you are going to handle with a particular component, especially defining an action name in your own namespace (com.mycompany.myapp.action.DO_SOMETHING or whatever). You can then make an Intent that matches your component, and use Intent.toUri() to get the URI representation of this. This can be placed in your link, and will then when pressed look for something that handles and and thus find your app. Note to be launched from the browser like this, the component's must handle the BROWSABLE category. (You don't need to have this in the Intent you put in the link, the browser will automatically add this in for you.)

This is a newer feature in the platform, which allows you to direct link intents to only your app so that other applications can not intercept and handle them.

In summary: read the regular documentation on intents and intent filters (such as the NotePad tutorial, though you won't be using content: URIs here, probably just custom actions) and get your app working that way. Then you can make a browser link to launch your app in the same way, provided your intent-filter handles the BROWSABLE category.

At first I thought that you didn't explain how ignoring the standard rules for URIs is bad, but then I found your other answer here.

@hackbod: Like Casebash, I am having problems with your instructions. Given an activity, I dump getIntent().toUri(Intent.URI_INTENT_SCHEME).toString(), paste that in a Web page (commonsware.com/sample), try opening it in a browser on the emulator, and I get choices of opening the page in Browser, Contacts, or Phone, but not my activity. That seems strange, considering that the intent: URI from toUri() has the component clause, so I'm not sure how those other apps can get it. I have the BROWSABLE category on the intent filter. If you have any thoughts, please @ me back. Thanks!

Don't bother trying this method if you want your URIs to reliably work; using intent URIs requires cooperation from the app taking the URI. zxing (Barcode Scanner) doesn't accept them (by deliberate design decision, apparently), so if you want to be able to scan barcodes to talk to your app (or take URI input from any other method you don't completely control), you either need to overload http:// (which requires a user choice between browser and your app) or just go with a custom scheme, which as far as I can tell passes transparently into the system and doesn't get caught up anywhere).

@hackbod can you please point me to w3c documentation which suggests to not implement new URI schemes? I have only found rfc2718 which seems to support that.

@hackbod - It appears this would not work with iOS though. It seems registering a unique scheme is the most cross-platform compatible implementation although I agree with you that it pollutes the namespace... developer.apple.com/library/ios/documentation/iPhone/Conceptual/

java - How to register some URL namespace (myapp://app.start/) for acc...

java android browser
Rectangle 27 39

Create an intent filter in the activity you want to load in the manifest like this:

<intent-filter>
    <action android:name="com.bubblebeats.MY_CUSTOM_ACTION" />
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
intent:#Intent;action=com.bubblebeats.MY_CUSTOM_ACTION;end
<body>
    <a href="intent:#Intent;action=com.bubblebeats.MY_CUSTOM_ACTION;end">click to load apk</a>
</body>

You can generate the URI from within your Android code like this:

Intent i = new Intent();

i.setAction("com.bubblebeats.MY_CUSTOM_ACTION");
i.putExtra("some_variable", "123456");

Log.d("ezpz", i.toUri(Intent.URI_INTENT_SCHEME));
04-13 09:47:30.742: DEBUG/ezpz(9098): intent:#Intent;action=com.bubblebeats.MY_CUSTOM_ACTION;S.some_variable=123456;end

You just want this part:

intent:#Intent;action=com.bubblebeats.MY_CUSTOM_ACTION;S.some_variable=123456;end

Take a good look at what occurred here and you can see how you can skip the code step and manually create these URIs yourself.

S.some_variable=123456

What does the package (from intent.setPackage(..) serialize out to?

Looks like the package is appended like package=com.bubblebeats; (Also, while not evident in this example, the package is URI encoded)

@Jason, were you able to get this to work? Launching the intent via "adb shell am start 'intent:#Intent..." works for me. However, from a browser, clicking on the linnk intent doesn't trigger the app launching.

This is the best ans i see in all the answers.

Where does the S. syntax is documented? Just relying on the output of toUri() doesn't seem a good idea.

java - How to register some URL namespace (myapp://app.start/) for acc...

java android browser
Rectangle 27 37

Create an intent filter in the activity you want to load in the manifest like this:

<intent-filter>
    <action android:name="com.bubblebeats.MY_CUSTOM_ACTION" />
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
intent:#Intent;action=com.bubblebeats.MY_CUSTOM_ACTION;end
<body>
    <a href="intent:#Intent;action=com.bubblebeats.MY_CUSTOM_ACTION;end">click to load apk</a>
</body>

You can generate the URI from within your Android code like this:

Intent i = new Intent();

i.setAction("com.bubblebeats.MY_CUSTOM_ACTION");
i.putExtra("some_variable", "123456");

Log.d("ezpz", i.toUri(Intent.URI_INTENT_SCHEME));
04-13 09:47:30.742: DEBUG/ezpz(9098): intent:#Intent;action=com.bubblebeats.MY_CUSTOM_ACTION;S.some_variable=123456;end

You just want this part:

intent:#Intent;action=com.bubblebeats.MY_CUSTOM_ACTION;S.some_variable=123456;end

Take a good look at what occurred here and you can see how you can skip the code step and manually create these URIs yourself.

S.some_variable=123456

What does the package (from intent.setPackage(..) serialize out to?

Looks like the package is appended like package=com.bubblebeats; (Also, while not evident in this example, the package is URI encoded)

@Jason, were you able to get this to work? Launching the intent via "adb shell am start 'intent:#Intent..." works for me. However, from a browser, clicking on the linnk intent doesn't trigger the app launching.

This is the best ans i see in all the answers.

Where does the S. syntax is documented? Just relying on the output of toUri() doesn't seem a good idea.

java - How to register some URL namespace (myapp://app.start/) for acc...

java android browser
Rectangle 27 3

/**** @author RAJESH Kharche */
//open Netbeans
//Choose Java->prject
//name it GoogleSearchAPP

package googlesearchapp;

import java.io.*;
import java.net.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

public class GoogleSearchAPP {
    public static void main(String[] args) {
        try {
            // TODO code application logic here

            final int Result;

            Scanner s1=new Scanner(System.in);
            String Str;
            System.out.println("Enter Query to search: ");//get the query to search
            Str=s1.next();
            Result=getResultsCount(Str);

            System.out.println("Results:"+ Result);
        } catch (IOException ex) {
            Logger.getLogger(GoogleSearchAPP.class.getName()).log(Level.SEVERE, null, ex);
        }      
    }

    private static int getResultsCount(final String query) throws IOException {
        final URL url;
        url = new URL("https://www.google.com/search?q=" + URLEncoder.encode(query, "UTF-8"));
        final URLConnection connection = url.openConnection();

        connection.setConnectTimeout(60000);
        connection.setReadTimeout(60000);
        connection.addRequestProperty("User-Agent", "Google Chrome/36");//put the browser name/version

        final Scanner reader = new Scanner(connection.getInputStream(), "UTF-8");  //scanning a buffer from object returned by http request

        while(reader.hasNextLine()){   //for each line in buffer
            final String line = reader.nextLine();

            if(!line.contains("\"resultStats\">"))//line by line scanning for "resultstats" field because we want to extract number after it
                continue;

            try{        
                return Integer.parseInt(line.split("\"resultStats\">")[1].split("<")[0].replaceAll("[^\\d]", ""));//finally extract the number convert from string to integer
            }finally{
                reader.close();
            }
        }
        reader.close();
        return 0;
    }
}

hey if you want me to sent you the content returned by link in the object i surely will.

You seem to have reused the code from the answer by @JoshM. However, you have modified and extended the code. What was the reason to do so? What does your code better/differently than that of @JoshM? Such kind of explanation would help readers to understand your solution.

I just tried Josh's code, didn't work. Tried Rajesh's class and it did.

@DavidH.Bennett Any reason why the difference?

java - easiest (legal) way to programmatically get the google search r...

java google-search
Rectangle 27 4

First of all, you need to define a custom action in your manifest file:

<activity
    android:name=".activity.MainActivity"
    android:label="@string/app_name_full">
    <intent-filter>
        <action android:name="com.yourpackage.action.OPEN_VIEW"></action>
        <category android:name="android.intent.category.DEFAULT"></category>
        <category android:name="android.intent.category.BROWSABLE"></category>
    </intent-filter>
</activity>

Then, for the content on your website, you need to generate the URI from an intent. Put following code in your Activity (This code could be removed, once the link is generated):

Intent i = new Intent();
        i.setAction("com.yourpackage.action.OPEN_VIEW");
        i.setPackage("com.yourpackage");
        i.putExtra("myextra","anystring");
        Log.d(getClass().getSimpleName(), i.toUri(Intent.URI_INTENT_SCHEME));

To receive the Extras, put following in your activity, that is able to recieve the custom action (as defined in manifest):

final Intent intent = getIntent();
final String action = intent.getAction();

        if ("com.yourpackage.action.OPEN_VIEW".equals(action)) {
           Log.i(getClass().getSimpleName(), "EXTRA: "+intent.getExtras().getString("myextra"));
        }

On your website (this is the previously generated link):

<a href="intent:#Intent;action=com.yourpackage.action.OPEN_VIEW;package=com.yourpackage;S.myextra=anystring;end">Open App with extra</a>

Hope that helps someone for better understanding. Please correct me, if I got something wrong.

java - How to register some URL namespace (myapp://app.start/) for acc...

java android browser
Rectangle 27 4

First of all, you need to define a custom action in your manifest file:

<activity
    android:name=".activity.MainActivity"
    android:label="@string/app_name_full">
    <intent-filter>
        <action android:name="com.yourpackage.action.OPEN_VIEW"></action>
        <category android:name="android.intent.category.DEFAULT"></category>
        <category android:name="android.intent.category.BROWSABLE"></category>
    </intent-filter>
</activity>

Then, for the content on your website, you need to generate the URI from an intent. Put following code in your Activity (This code could be removed, once the link is generated):

Intent i = new Intent();
        i.setAction("com.yourpackage.action.OPEN_VIEW");
        i.setPackage("com.yourpackage");
        i.putExtra("myextra","anystring");
        Log.d(getClass().getSimpleName(), i.toUri(Intent.URI_INTENT_SCHEME));

To receive the Extras, put following in your activity, that is able to recieve the custom action (as defined in manifest):

final Intent intent = getIntent();
final String action = intent.getAction();

        if ("com.yourpackage.action.OPEN_VIEW".equals(action)) {
           Log.i(getClass().getSimpleName(), "EXTRA: "+intent.getExtras().getString("myextra"));
        }

On your website (this is the previously generated link):

<a href="intent:#Intent;action=com.yourpackage.action.OPEN_VIEW;package=com.yourpackage;S.myextra=anystring;end">Open App with extra</a>

Hope that helps someone for better understanding. Please correct me, if I got something wrong.

java - How to register some URL namespace (myapp://app.start/) for acc...

java android browser
Rectangle 27 1

The only way I can think to do this would involve a signed, Java applet running on your page. Essentially what you'd do is provide the file to the applet and have it open up a new browser window with the file's URL. Since the applet is trusted by the local system it should have access to the local hard drive and should be able to start up a new application.

Note: I've not tried this, I'm just speculating on how I would do it. I have used a signed, Java applet to get at some local networking parameters for use in a Wake on LAN application so I know that signed applets are allowed to interact with the system in ways that browsers can't.

To me it seems a bit of an overkill for a redirection problem like this: I don't need any access to the local system, just provide the browser with an address to go to :)

I don't think the browser will let you open a local resource from a web page loaded from a remote system. This would be a security violation. A signed applet, because it has to be approved to access local resources can get around this.

javascript - Remote site, local file redirection - Stack Overflow

javascript firefox redirect firefox-addon
Rectangle 27 2

Have a read here.

window.history.pushState('abc', "Title", "/new-url");
NOTE : window.history.pushState('abc', "Title", "/new-url");

java - just add url on only address bar of browser - Stack Overflow

java javascript jquery
Rectangle 27 2

Have a read here.

window.history.pushState('abc', "Title", "/new-url");
NOTE : window.history.pushState('abc', "Title", "/new-url");

java - just add url on only address bar of browser - Stack Overflow

java javascript jquery
Rectangle 27 17

  • Export the SSL certificate using Firefox. You can export it by hitting the URL in the browser and then select the option to export the certificate. Let's assume the cert file name is your.ssl.server.name.crt
JRE_HOME/bin
JDK/JRE/bin
keytool -keystore ..\lib\security\cacerts -import -alias your.ssl.server.name -file .\relative-path-to-cert-file\your.ssl.server.name.crt

If asked for a password, use the default cacerts keystore password changeit (stackoverflow.com/a/22782035/1304830). Also be sure to run cmd as administrator.

ssl - Java: sun.security.provider.certpath.SunCertPathBuilderException...

java ssl https ssl-certificate
Rectangle 27 17

  • Export the SSL certificate using Firefox. You can export it by hitting the URL in the browser and then select the option to export the certificate. Let's assume the cert file name is your.ssl.server.name.crt
JRE_HOME/bin
JDK/JRE/bin
keytool -keystore ..\lib\security\cacerts -import -alias your.ssl.server.name -file .\relative-path-to-cert-file\your.ssl.server.name.crt

If asked for a password, use the default cacerts keystore password changeit (stackoverflow.com/a/22782035/1304830). Also be sure to run cmd as administrator.

ssl - Java: sun.security.provider.certpath.SunCertPathBuilderException...

java ssl https ssl-certificate
Rectangle 27 1

blackberry browser getdefaultsession

yes thank u so much but i already did that but i dont know what to import

i'm using netbeans and i'm new with it so would u plz tell me what to import to identify the class Browser

import net.rim.blackberry.api.browser.Browser

however, maybe your problem is that you are using NetBeans? As far as I am aware, NetBeans is not a supported platform for developing for the BlackBerry. You need to use either RIM's JDE or Eclipse. RIM's site about developing Java apps for BlackBerry: us.blackberry.com/developers/javaappdev

java - Blackberry browsing problem - Stack Overflow

java url browser blackberry java-me
Rectangle 27 1

Can't be done. This is a security feature to make it harder to spoof a site (e.g. for phishing attacks)

The domain can't be changed. The rest of the URL can. Thus no possibility of spoofing.

java - just add url on only address bar of browser - Stack Overflow

java javascript jquery