How to open the Amazon AppStore directly from my Android application? - android

I have seen answers regarding Amazon Appstore from iPhone but not from Android. I'm trying to make a button that will open the Amazon Appstore (for android) on my app's page.
Here is how it's done for Google Play:
final String appPackageName = context.getPackageName();
try {
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName));
} catch (android.content.ActivityNotFoundException e) {
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName));
}
How should I replace the Strings so that it works "the same" for the Amazon AppStore?

The Amazon app store URI is
amzn://apps/android?
Directing to a particular app would look like
amzn://apps/android?p=com.amazon.mp3
Source: Linking To the Amazon Appstore for Android

Look into WebViews. It does exactly what you want, you can open a page in your own app. Simply define a webview in the xml, and use the java to display the page.
How to do it without webview:
(From docs)
By default, a WebView provides no browser-like widgets, does not
enable JavaScript and web page errors are ignored. If your goal is
only to display some HTML as a part of your UI, this is probably fine;
the user won't need to interact with the web page beyond reading it,
and the web page won't need to interact with the user. If you actually
want a full-blown web browser, then you probably want to invoke the
Browser application with a URL Intent rather than show it with a
WebView. For example:
Uri uri = Uri.parse("http://www.example.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
With webview:
webview.loadUrl("http://slashdot.org/");
// OR, you can also load from an HTML string:
String summary = "<html><body>You scored <b>192</b> points.</body></html>";
webview.loadData(summary, "text/html", null);
Let me know if this works by commenting.

Related

Open Facebook native app from your android app

My question is directly connected with this one Open Facebook page from Android app? Which answer (for the version at the moment) is not the marked one but this one
public static Intent newFacebookIntent(PackageManager pm, String url) {
Uri uri;
try {
pm.getPackageInfo("com.facebook.katana", 0);
// https://stackoverflow.com/a/24547437/1048340
uri = Uri.parse("fb://facewebmodal/f?href=" + url);
} catch (PackageManager.NameNotFoundException e) {
uri = Uri.parse(url);
}
return new Intent(Intent.ACTION_VIEW, uri);
}
Which is confirmed working last on 7th of February 2015.
My question is should you use the whole url (like www.facebook.com/mypage) or just add the url of the page so it'll be fb://facewebmodal/f?href=mypage. I tried both and it just opens the fb app without an actual page. It shows blank fb page on both tries.
Can someone give me an example with url for some public page that works?
You can try to write mypage as https://www.facebook.com/ID. The whole uri should then be
fb://facewebmodal/f?href=https://www.facebook.com/ID
and change ID to the page you want to visit.
That functionality is not documented or supported, so you may get unknown result. You may want to try passing the Page ID or Profile ID instead of names. You can get the ID by calling https://graph.facebook.com/<name> and parse the result.
I had the same issue. I searched for a while and tried all the answers on here Open facebook page from android app (in facebook version > v11) and there Open Facebook page from Android app?, finally I figured out what the real problem is. There is nothing wrong in the code, however the weird behavior is about facebook app itself. If the facebook app is on the background, it just switches back to the foreground without navigating to the requested page. You just swipe it out from the background (kill instances) and try your code again.
Considering most of the users leave facebook app on the background, this is some kind of an issue needs to be fixed. Although I think it is about the facebook app itself, somehow it can be related with the device. I'm using Nexus 6 with v 6.0.1 and had no chance to test it on another android versioned device.
i using this for my apps its working just fine, kotlin
try {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/100674618166286"));
startActivity(intent);
} catch(e: Exception) {
startActivity( Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/iqtousd")));
}
Remember have a similar issue.
Try the mobile url :
instead of
String facebookUrl = "https://facebook.com/...";
use
String facebookUrl = "https://m.facebook.com/...";

ACTION_GET_CONTENT to Google Images

As the docs say: "ACTION_GET_CONTENT could allow the user to browse over the web and download the desired data".
And that's what I need, from Google Images. Although, if I use this intent's type the app crashes (I suppose it only expects ACTION_VIEW to open the browser):
Intent intent = new Intent();
intent.setData(Uri.parse(url));
intent.putExtra("return-data", true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, PICK_IMAGE);
It needs to (edited to clarify what I need):
Estabilish the connection to the web browser
The URL to Google Images
Retrieve the image's URL after the user has chosen one (it needs to close the browser, the ACTION_VIEW just keeps on going until the user decides to close it and does not retrieve any information).
As far the URL I have is this one, but it needs something else because it is going to a default search, not for images:
String url = "http://images.google.com/search?q=" + imagename;
I appreciate any help.
Try using the following url. It works fine for me in my app:
"http://images.google.com/search?num=10&hl=en&site=&tbm=isch&source=hp&biw=980&bih=710&q=" + YourQueryString
You need the tbm query parameter set to the value isch for image search. So the minimal URL would look like:
"http://google.com/search?tbm=isch&q=" + queryString

Setting default browser for activity programmatically

I'm developing an android app and among other functionality I need to open some urls in external web browser. Can I programmatically set a default application for that, so the user won't be able to choose from the list of available browsers? I mean, I want to set default browser only for my app but not for the whole operating system.
Yes, for this you can force your application to always open native android browser only. For this you have to identify the launching Activity of Browser application, something like this:
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.google.android.browser","com.google.android.browser.BrowserActivity"));
intent.setAction("android.intent.action.VIEW");
intent.addCategory("android.intent.category.BROWSABLE");
Uri uri = Uri.parse(url);
intent.setData(uri);
try
{
startActivity(intent);
}
catch (Exception e)
{
e.printStackTrace();
}
You can use .setPackage for the intent: http://developer.android.com/reference/android/content/Intent.html#setPackage(java.lang.String) . Call it with the browser's package name (defined in its manifest, package attribute).
I'm using something similar for firing up the Google+ application for sharing a string:
Intent shareIntent = ShareCompat.IntentBuilder.from(getActivity())
.setText("Dummy string to share")
.setType("text/plain")
.getIntent()
.setPackage("com.google.android.apps.plus");
startActivity(shareIntent);
In my example, "com.google.android.apps.plus" is the package name for the Google+ application.
Sharedpreference for Browser class is "MODE_private" , so we can't access the home_page changing steps directly programatically,
iff we want to do, we should do through Browser.java opensource code and we should get some idea from there itself.

Launch custom Android application from WebView

I have an HTML file which is launching an app if I open it in the Android native browser,
but when I try to open the same in a WebView, it is not able to launch that application, and "Webpage not available" is shown. I think my WebView is not able to handle the scheme "my.special.scheme://" defined for the application.
I read Launching an Android Application from the Browser, but it does not cover information about launching an app from a WebView.
It's true, links with a custom URI scheme don't load automatically launch apps from a WebView.
What you need to do is add a custom WebViewClient to your WebView:
webView.setWebViewClient(new CustomWebViewClient());
and then in the shouldOverrideUrlLoading(), have the following code:
public boolean shouldOverrideUrlLoading(final WebView webView, final String url) {
if (url.startsWith("my.special.scheme://")) {
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
// The following flags launch the app outside the current app
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
activity.startActivity(intent);
return true;
}
return false;
}
I'm not sure, but I believe that WebView simply doesn't handle custom URI schemes.
The workaround is to override WebViewClient.shouldOverrideUrlLoading() and manually test if the URL uses your URI scheme, launching your app and returning true if it matches, otherwise returning false.
I perform an ACTION_VIEW with the URL to make the URL open in the default browser, which will do the redirecting to the concerning app (I had to fix this concerning payments via a bank app)

Opening Facebook app with another ? With the "Twitter way"

My app needs to display a Facebook account. So I would like the Facebook application opens or if it is not available, the web browser. Currently I can open the Twitter app with this way and the system ask what to do (Twitter app or the browser).
Here is the code:
WebView myWebView = (WebView) findViewById(R.id.webViewProfile); // Create an instance of WebView and set it to the layout component created with id webview in main.xml
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadUrl("https://mobile.twitter.com/"+name); // Specify the URL to load when the application starts
myWebView.setInitialScale(1); // Set the initial zoom scale
myWebView.getSettings().setBuiltInZoomControls(true); // Initialize zoom controls for your WebView component
myWebView.getSettings().setUseWideViewPort(true); // Initializes double-tap zoom control
myWebView.getSettings().setUserAgentString("BumpMe");
This method is very good and I want to have the same result for Facebook. Currently I can open the Facebook app like that:
String uri = "facebook://facebook.com/info?user="+fbid;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
context.startActivity(intent);
But if the application is not installed it won't work...
How can I do it like for twitter ?
Thanks
The reason this works with Twitter is that the Twitter app handles https://mobile.twitter.com/* URL's in its intent filters; so when you issue an intent that has that URL, the Twitter app gets called. So the only way to do this with Facebook (or any other app) would be to use a URL that matches one of the patterns declared in its intent filters. Maybe http://m.facebook.com/... ?
Instead of offering the user the choice of app or browser, another way is to try to open the app, and if that fails to open the web page. Here is how I do that for Twitter:
long userID = tweet.getUser().getId();
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=" + userID));
startActivity(intent);
}catch (Exception e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/intent/user?user_id=" + userID)));
}

Categories

Resources