Android Link to Market from inside another app - android

I am building many apps for Android and wish to have a menu button in the apps that basically opens a list of my other apps in the Android Market.
Is there a way to create an intent and have the Android market pop up with a search (of my company) in the market so users can buy other apps?
ian

Even better to use "market://details" instead of "market://search":
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.android.example"));
startActivity(intent);
Then it opens directly the details page of the app. With search it shows a single search result and the user has to do an additional click to get to the detail page.

Yes, there is a documented Intent syntax for that (http://market.android.com/search?q=pub:<Developer Name> or market://search?q=pub:<Developer Name>).

The intent action would be view, and uri the market url/uri.
Like this:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pub:<developer name>") ) );

Another way is to launch a URL Intent with your application's package name in it.
User will get popup with list of installed Browsers + Play Store app in which he can view your target app.
String appPackageName = "com.example.android";
String url = "https://play.google.com/store/apps/details?id=" + appPackageName;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
Above code is tested and works as expected on Play Store version 4.1.6

On my real devices Sony Xperia Pro and PocketBook tablet, even when you put a link to play web store e.g. https://play.google.com/store/apps/details?id=com.estrongs.android.pop
It will ask if you want to open it in the default browser or in the Play market.
If you select Play market - application is shown as expected.
Did not test it with intent, tested with Autolink from TextView.

#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.adfree:
final String appPackageName = "com.zooohooo.noads"; // Can also use getPackageName(), as below
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
return true;
case R.id.rate:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName())));
return true;
}
return super.onOptionsItemSelected(item);
}

Related

Intent to open a chat with a specific user on snapchat app

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

How to open links in Android app in external browser?

Can anyone help me in Code for opening links in external browsers or other Android app?
Now the case is the link is opening in the app itself. But if the link belongs to an android app its not opening. It's showing install the Android app.
So I want that if the link can be opened in browsers, then it will ask from a list of browsers. Or if the links belongs to an app it must show the app in the list too.
Something like this could work
Intent browserIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.google.com"));
startActivity(browserIntent);
As #zain posted ago you can use.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.stackoverflow.com"));
startActivity(intent);
But if you have more then one browser installed in device and want to choose from one of them. Use intent chooser like this
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.stackoverflow.com"));
// Always use string resources for UI text. This says something like "Share this photo with"
String title = getResources().getText(R.string.chooser_title);
// Create and start the chooser
Intent chooser = Intent.createChooser(intent, title);
startActivity(chooser);
refer from here
Show browser list when opening a link in android
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.co.in/"));
String title = "Complete Action Using";
Intent chooser = Intent.createChooser(intent, title);
startActivity(chooser);
If you are in a WebView in your App, and on clivking a link there, if the app opens the link in the App Itself, Then possibly u should have overridden this method.
myWebView.setWebViewClient(new WebViewClient()
{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
//view.loadUrl(url);
return false;
}
});
The return of false should ask the user, where to Open the link. With the browsers installed in the mobile

using deep linking in android with adds

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.

Android Intent to launch Google+ app at Google+ Community screen

There is already a good SO question for displaying a Google+ Page in the Google+ Android app:
Open Google Plus Page Via Intent In Android
But what about the Intent to launch the Google+ app at a specific Google+ Community?
EDIT - to the silent down-voters, please explain why you down-voted.
My solution, working with G+ version "5.3.0.91034052", tested today
final Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( "https://plus.google.com/communities/107847486351510098159" ) );
intent.setPackage( "com.google.android.apps.plus" );
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity( intent );
}
It's not bullet proof, you need Google+ app on your device, in case you don't have it some kind of try-catch might be nice (?),
I achieved this by using:
String communityPage = "communities/123456789";
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.google.android.apps.plus",
"com.google.android.apps.plus.phone.UrlGatewayActivity");
intent.putExtra("customAppUri", communityPage);
startActivity(intent);
} catch(ActivityNotFoundException e) {
// fallback if G+ app is not installed
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/"+communityPage)));
}
Where 123456789 is the id of the community copied from the address bar.
Just in case anyone else needs to do this I had to do this in my app and used the below code
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/communities/1234356789")));
Where 1234356789 is the community id from the address bar.
This then prompts whether you want to open with Google+ or browser.

Open page in Facebook,Twitter and Google Plus app from other app - Android

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

Categories

Resources