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.
Related
How can I launch youtube app using intent
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setPackage("com.google.android.youtube");
intent.setData(Uri.parse("https://www.youtube.com/watch?v=3TKSW-VgVyM"));
startActivity(intent);
The above code plays the video in youtube, but I want to open only youtube app, How Can I achieve this? Thanks in advance
you can open it using the package name com.google.android.youtube
start application knowing package name
Intent.getLaunchIntentForPackage("com.google.android.youtube");
This is the code needed for launching the Youtube app. Using this inside an onclicklistener is probably best.
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.google.android.youtube");
startActivity( launchIntent );
I have an Android app that can open another app I have using:
Intent intent = new Intent();
PackageManager manager = getPackageManager();
intent = manager.getLaunchIntentForPackage("myOtherAppPackageName");
intent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(intent);
Which works perfectly, the only thing is the app force closes when I don't have the other app installed, which makes perfect sense. My question is how do I get my app to open the Play Store to the specific app for someone to download if they do not already have the other app? I would assume do the exact same thing except I don't have the package name for the Play Store.
if you have the package name you can just do this
Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
"market://details?id=" + "packagename"));
startActivity(marketIntent);
that will launch the play store on the page for that application
If you know package lets use this example code:
public void offerApp(Activity activity) {
Log.d("Launching Market");
Intent i = new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=<PACKAGE>"));
activity.startActivity(i);
}
I can open my local html file with android browser by following way:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(webPageUri, "text/html");
intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
startActivity(intent);
And it works. But I would like to open my local html file in default browser without specifing:
intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
Is there a way to to that?
Edit:
If I remove setClassName as you suggest, it opens in HtmlViewer (it is not a default browser).
And if I do it like that:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(webPageUri);
startActivity(intent);
I get: ActivityNotFoundException
Just use:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(webPageUri, "text/html");
startActivity(intent);
This will give the user a list of installed browsers to choose from. If there is only one browser, then that's the one that will be launched.
Just remove the setClassName() line and you are set to go.
This will launch the default browser if it is the only browser in the phone. If there are more than one, the user will have to select one.
I'm trying to open market app from my app using:
Intent i = new Intent("Intent.ACTION_VIEW");
i.setData(Uri.parse("market://details?id=com.compamy.app"));
startActivity(i);
But I have No Activity Found Error. I am using real device and I have market installed.
So my question is: What can be done here?Thanks.
The only problem here is what zapl pointed out in the comments ("" around the action). The documentation (http://developer.android.com/guide/publishing/publishing.html) clearly states how to use this:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.example.android"));
startActivity(intent);
official documantation link:
http://developer.android.com/guide/publishing/publishing.html#marketintent
Opening the app details page from your Android app
To open the Google Play details page from your application, create an intent with the ACTION_VIEW action and include a data URI in this format:
market://details?id=
For example, here's how you can create an intent and open an application's details page in Google Play:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.example.android"));
startActivity(intent);
Try this:
Uri uri = Uri.parse("market://details?id=com.compamy.app");
Intent i = new Intent(Intent.ACTION_VIEW, uri);
startActivity(i);
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.