Opening application from current application - android

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);
}

Related

deep linking android app

hey I want to utilize deep linking/ app indexing concept in android app. for instance, by clicking on a button another app can open a custom activity of mine. I have seen many tutorials to open website from android app but i didn't see any for app content.
I tried this small code but actually not what i'm looking for.
Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
if (intent!=null) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
else {
//Log.d("NULL", "NULL");
Uri uri = Uri.parse("http://play.google.com/store/apps/details? id=packageName");
Intent go = new Intent(Intent.ACTION_VIEW, uri);
startActivity(go);
}

Can't open Market App from my Application

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);

Coming back from Android Market does not show app again

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

How to open the default android browser without specifying an URL?

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.

Is there a way to direct the user to the market for another app?

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.

Categories

Resources