How to open specific page of another app on clicking add in app in android ? I am creating an android app in which add are showing .when clicking on that add it opens the play store. But i want to open specific page of that app using deeplinking. e.g am getting snapdeal offers add in my application when i click on that add it open the specific page of snapdeal.How to do that ?
Add the package name of the app you want to open in playstore:
String appPackageName = "package_xy"; // eg. com.twitter.android
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
}catch (android.content.ActivityNotFoundException e) {
//if playstore app not installed
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
}
So you probably would need your advertisement to send the package name of their app with it. Or just an url to open (maybe send the playstore browser link in the catch above if its an app, so you could detect the play.google.com part and replace accordingly or just open the plain website if its not a playstore url).
You asked what happens if the app is already installed: Still the same. You should check for it first:
Intent i;
PackageManager manager = getPackageManager();
String appPackageName = "package_xy";
try {
i = manager.getLaunchIntentForPackage(appPackageName);
if (i == null)
throw new PackageManager.NameNotFoundException();
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
} catch (PackageManager.NameNotFoundException e)
{
//open playstore instead
}
So this is only one of many ways. If the app is not found on the device, the try will fail and catch is executed. If it is found it will be opened.
In the case of twitter I even could open it with a deeplink like this:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://status?status_id="+id));
For some things like PDF there are ways to open the applicationpicker, but I don't think thats what you need in this case.
You should be fine if you use the above code. Just put the first snippet in the catch of the second one and you should be fine.
Related
I am working on my app which will show my website and i am getting intent error in my Android Webview app whenever I try to open Instagram profile. I want it to be open in my Instagram app can someone help me out by code please
Please help me out Click here to see the error I got
Seems that url you created could be invalid, try to create your intent with urls like these:
Uri uri = Uri.parse("http://instagram.com/_u/xxx");
Intent likeIng = new Intent(Intent.ACTION_VIEW, uri);
likeIng.setPackage("com.instagram.android");
try {
//instagram app exists on device
startActivity(likeIng);
} catch (ActivityNotFoundException e) {
//instagram app does not exist on device, using browser
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://instagram.com/xxx")));
}
Hi there I just finished my first app for Android that I want to publish. In my app I have a button which allows users to share the link, to my app in the Google Play Store. Now I don't know how to get that link, because my app isn't published yet. Thanks.
https://play.google.com/store/apps/details?id=<YOUR_PACKAGE_NAME>
Replace <YOUR_PACKAGE_NAME> by your package name
the right practice is to call the view intent by market schema using your package name like below:
String yourPackageName = getPackageName();
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + yourPackageName)));
}
catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + yourPackageName)));
}
You need to know the app's package name which is declared in manifest file.You can link your app -
From an Android app:-
market://details?id=<package_name>
From a web site-
http://play.google.com/store/apps/details?id=<package_name>
I'm trying to find if there is any app schema,
to open the Snapchat app (via Intent) with a specific userID that I want to chat with?
BTW, to find the userID:
This the only thing that works for me. Unfortunately, it adds the extra step of making the user choose the browser or Snapchat app.
Intent nativeAppIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://snapchat.com/add/" + snapchatId));
startActivity(nativeAppIntent);
Oddly enough, the URL scheme snapchat://add/" + snapchatId works on iOS but not on Android (it opens the Android app, but does not pop up the user).
EDIT: Add intent.setPackage("com.snapchat.android"); and it will open the app without the chooser. But adding this means you will need to surround everything with a try/catch to prevent a crash.
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://snapchat.com/add/" + snapchatId));
intent.setPackage("com.snapchat.android");
startActivity(intent);
} catch (Exception e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://snapchat.com/add/" + snapchatId)));
}
I try to add "rank this app" button in my app
Uri uri = Uri.parse("market://details?id=" + context.getPackageName());
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
goToMarket.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(goToMarket);
then I get Error "Android : No Activity found to handle Intent"
BTW : I use SurfaceView I don't know if it is important
This might happen because:
You're on a device where Google Play is not installed (for example, a device that's not an official Android device).
Google Play is installed, but disabled (make sure it's not disabled in the settings menu).
It's a rooted device and there is something nonstandard interfering with the intent launch/match mechanism.
Add try catch to prevent from crash, if there is no market app is installed in your device
try
{
context.startActivity(goToMarket);
}
catch (Exception e)
{
//Show Toast
}
I'm working on an application where I need to integrate the social functionality of the different social networks: Facebook, Twitter, Google+.
For now, in Facebook and Twitter i'm recognized if the user has a native application and if he does, I'm opening it and show him my fan page.
For Twitter I use the next code:
try {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("twitter://user?screen_name=[user_name]"));
startActivity(intent);
}catch (Exception e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("https://twitter.com/#!/[user_name]")));
}
And for Facebook the next code:
try{
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/" + PROFILE_FACEBOOK_APP_ID));
startActivity(intent);
}catch(Exception e){
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/UserNamePage")));
}
Now I want to do the same thing for Google+. I saw that I can browse to my fan page with the next Url https://plus.google.com/MY_PAGE_ID/, but it keep asking me if I want to open it with Google+ application or with the browser, and I want that he will open it with the application automatically, without asking the user.
Is there a simple way to do this?
Thanks.
Found a solution:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.google.android.apps.plus",
"com.google.android.apps.plus.phone.UrlGatewayActivity");
intent.putExtra("customAppUri", "FAN_PAGE_ID");
startActivity(intent);
I think this is quite safe, because we do not need to specify the component, just the google+ app package name:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://plus.google.com/[Google+ID]/"));
intent.setPackage("com.google.android.apps.plus"); // don't open the browser, make sure it opens in Google+ app
startActivity(intent);
Unknown if google plus needs some other information in the Intent but as general Android solution you can explicitly set the target. You will need the package name of google+.
More info here: http://developer.android.com/reference/android/content/Intent.html#setPackage%28java.lang.String%29
For example:
Intent.setPackage("com.google.android.apps.plus"); //Don't know the exact package name