I am new for Robotium. I am trying to launch Android Browser with Robotium. Thanks!
You can do it this way:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getInstrumentation().getContext().startActivity(i);
However it will open another application and you will not be able to do anything else with robotium.
Robotium can be used for accessing views inside the application. Since browser is another application you cannot access it.
Only you can just launch a browser using the following code
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
Context instrumentationContext=getInstrumentation().getContext();
instrumentationContext.startActivity(browserIntent);
Related
I am developing an android application. I am currently opening a new activity with WebView when the user click on a URL. I want to change it load the URL inside the the browser. How is that possible?
Simply do like this.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(intent);
I have an Android SDK that uses a web view to show some pages, but depending on the requested link, I have it open an external browser. I am using the WebView's shouldOverrideUrlLoading method, and if it's a link to be opened externally, I use:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
This works for us in a demo app, but someone integrating our SDK says that it's opening within the web view. I don't have access to their code, but what is the developer able to do on his side to prevent the default action to open an external browser? I have thought of two possible solutions that I found on SO:
Use some flags to make sure no existing tasks are used, like so:
Intent i = new Intent(Intent.ACTION_VIEW);
Bundle b = new Bundle();
b.putBoolean("new_window", true); //sets new window
i.putExtras(b);
i.addCategory(Intent.CATEGORY_BROWSABLE);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
i.setData(Uri.parse(url));
startActivity(i);
Would this be sufficient?
Another solution is to force opening in the chrome browser, like so:
Intent intent=new Intent(Intent.ACTION_VIEW,Uri.parse(urlString));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setPackage("com.android.chrome");
context.startActivity(intent);
What would be the preferable solution? Or am I missing anything else?
I am starting market intent to go my app. It starts well and also showing my app. But problem with this is when pressing back, it is not coming to my my app again. Also when pressing home in market, again launch app, it shows market page instead of app.
Here is the code which i am using.
Intent marketIntent = new Intent(Intent.ACTION_VIEW);
marketIntent.setData(Uri.parse("market://details?id=" + AndroidUtils.getPackageName()));
marketIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(marketIntent);
Thanks in advance!
use
Intent marketIntent = new Intent(Intent.ACTION_VIEW);
marketIntent.setData(Uri.parse("market://details?id=" + AndroidUtils.getPackageName()));
startActivity(marketIntent);
don't use the flags because the activities are cleared when u use these flags
I'm loosing my mind over this. I want to open the user's default web browser. I can use this:
startActivity( new Intent( Intent.ACTION_VIEW, Uri.parse("http://google.com")));
To open the browser and send the user to that URL. But I don't want to send him to a specific URL, I just want to open the browser. I'm sure it's a simple solution, I just can't find it. Any Ideas?
To just open the browser without any URL opened you can use
startActivity( new Intent( Intent.ACTION_VIEW, Uri.parse("about:blank")));
After a bunch of searching, I was able to do this:
PackageManager pm = getPackageManager();
Intent queryIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
ActivityInfo af = queryIntent.resolveActivityInfo(pm, 0);
Intent launchIntent = new Intent(Intent.ACTION_MAIN);
launchIntent.setClassName(af.packageName, af.name);
startActivity(launchIntent);
It basically says "What application would handle this?". Then it grabs that applications package and class name then fires an intent for the main action.
I want to direct the user from one app the user is currently running, to the market, to download another app.
The link to the market is: market://search?q=pname:your.package.name
use this in your code:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.android.example"));
startActivity(intent);
from: http://developer.android.com/guide/publishing/publishing.html#marketintent
Yes. Try this:
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://market.android.com/details?id=com.hg.cyberlords"));
c.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
c.startActivity(intent);
This will open the market app with "Cyberlords" app.