I have a bunch of similar apps which the user might be interested in downloading.
I have a button 'get more of this' so when the user clicks on this button , it shows a link of other apps. Clicking on that link should take him to the download page in the
android market. I tried google but couldn't find any answers.
Can someone help?
Thanks
Try something like this for each app:
Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=your.app.package.name"));
marketIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(marketIntent);
You can also do a search:
Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pname:your.app.package.name"));
Related
is it possible to ask website visitors to save your website on their home-screen?
android
Check out this answer here, on how to create a shortcut:
How to add android bookmark on homescreen from web page?
If you're writing an Android app, you can use this approach. However, if this is a website, this approach will not work, as it looks like the Android Intent system ignores website generated actions.
you can create a web page shortcut on home screen using this code. Provide the necessary info like url, title etc..
final Intent in = new Intent();
final Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
long urlHash = url.hashCode();
long uniqueId = (urlHash << 32) | shortcutIntent.hashCode();
shortcutIntent.putExtra(Browser.EXTRA_APPLICATION_ID, Long.toString(uniqueId));
in.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
in.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
in.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(
BrowserBookmarksPage.this,
R.drawable.ic_launcher_shortcut_browser_bookmark));
in.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
//or in.setAction(Intent.ACTION_CREATE_SHORTCUT);
sendBroadcast(in);
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
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.
I have a code for opening URL with browser:
Intent i = new Intent(Intent.ACTION_VIEW, uri);
startActivity(i);
My question is, if user has set up default app for opening url, is there a way to override the default app and show application choose dialog instead?
i just found a solution. it was a so simple:
startActivity(Intent.createChooser(intent, title));
I do not know the exact answer to your question, but there is a bit more complicated decision. You can get a list of browsers, that installed on smartphone:
PackageManager manager = getPackageManager();
List<ResolveInfo> info = manager.queryIntentActivities(myIntent,PackageManager.MATCH_DEFAULT_ONLY);
And then create a choose dialog manually.
P.S. Maybe there is a more simple solution ...
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