So, from my app I can launch Chrome and get it to load a page using the http:// using the code below.
My problem is that when I try and load content that is stored locally on the device. i.e. file:///, I get the error further down.
Any ideas on how to work around this?
Code:
String urlString="file:///storage/emulated/0/Download/primer.html";
Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse(urlString));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setPackage("com.android.chrome");
startActivity(intent);
Error:
android.content.ActivityNotFoundException: No Activity found to handle
Intent { act=android.intent.action.VIEW
dat=file:///storage/emulated/0/Download/cuescript_primer.html
flg=0x10000000 pkg=com.android.chrome }
Related
I am trying to open the what3words app using the documentation here
https://developer.what3words.com/tutorial/mobile-linking-to-the-what3words-app/
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("w3w://show?threewords=daring.lion.race"));
startActivityForResult(intent, INTENT_CODE);
but I keep getting this issue
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=w3w://show?threewords=daring.lion.race}
I am on my device and have google play and the what3words app installed on the device.
Try opening the app like this:
Intent intent = packageManager.getLaunchIntentForPackage("{w3w package name}");
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("w3w://show?threewords=daring.lion.race"));
startActivity(intent);
To get the package name look for it in adb:
adb shell pm list packages
I have an instant app with two features with differents urls.
Launching the example.com/A from the android studio this code works nice, the activity B (or feature B) is opened.
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://example.com/id/"+mIds.get(mPager.getCurrentItem())));
intent.setPackage(getPackageName());
intent.addCategory(Intent.CATEGORY_BROWSABLE);
startActivity(intent);
But running the installed app, when I press the same button I get the error:
android.content.ActivityNotFoundException: No Activity found to handle Intent
{ act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE]
dat=https://example.com/... pkg=com.example.myapp }
Any idea?
When I open a link inside the Facebook app, it opens a new task for the browser while I can switch back to the Facebook app instead of opening the browser inside itself like an ordinary Activity. But when I launch an Intent to my application's Google Play page it behaves like an Activity inside my app instead of launching a separate instance for Google Play.
Here's how I'm starting the Intent:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=MY.APP.PACKAGE")));
I found this thread and wrote this snippet:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("market://details?id=MY.APP.PACKAGE"));
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
Which fails with this message in logcat:
04-29 12:35:42.681: E/AndroidRuntime(8482): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW cat=[android.intent.category.LAUNCHER] dat=market://details?id=MY.APP.PACKAGE flg=0x50000000 }
Any ideas?
You just need to remove the addCategory() call and it should work.
I'm trying to start the preferences activity in the native messenger client from my application. in AOSP Mms.apk does not have an intent filter setup on that activity. Regardless I'm trying to find a work around to launch the user into that screen.
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(ComponentName.unflattenFromString("com.android.mms/com.android.mms.ui.MessagingPreferenceActivity"));
intent.addCategory("android.intent.category.LAUNCHER");
try {
startActivity(intent);
} catch (Exception e) {
AppUtils.alertError(this, error);
}
I'm receiving
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.android.mms/.ui.MessagingPreferenceActivity } from ProcessRecord{406e2738 674:com.handmark.genericapp/10034} (pid=674, uid=10034) requires null
Any thoughts?
What you want is not possible. That activity is not exported (at least in the source code showing in Google Code Search), so you cannot start it, except by rewriting the app as part of your own custom firmware.
Also, bear in mind that this app may or may not exist on any given device.
I want to specifically run the default Android browser for a given URL. I'm using this code:
Intent i = new Intent();
i.setAction("android.intent.action.VIEW");
i.addCategory("android.intent.category.BROWSABLE");
i.setClassName("com.google.android.browser", "com.android.browser.BrowserActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setData(Uri.parse(url));
startActivity(i);
The error I receive is:
Unable to find explicit activity class {
com.google.android.browser/com.android.browser.BrowserActivity};
have you declared this activity in your AndroidManifest.xml?
I also tried filtering the intents by the package:
i.setPackage("com.google.android.browser");
instead of setClassName, but to no avail:
No Activity found to handle Intent { act=android.intent.action.VIEW
cat=[android.intent.category.BROWSABLE]
dat=http://www.google.com/ flg=0x10000000 pkg=android }
I also tried adding <uses-library android:name="com.google.android.browser" /> to the manifest.
Am I missing something here?
PS: I'm not interested in using startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"))) as it will list all the choices for the browsing Intent.
i use this, it's ok.
intent.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));
i think you know what wrong. :)
Please note the default browser can be overridden and it's not always the built in browser app, it can be for example Opera Mini.
You need to do this way:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("http://www.google.com");
intent.setData(data);
startActivity(intent);
One way to open an URL in a browser from code is to use a webview .
Create a WebViewClientClass that extends the WebViewClient like :
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
Then create a webview.
Set webview.setWebViewClient(new WebViewClientClass()); --- this is a small workaround so that the default web browser doesn't take over .
Then take the url in an edittext and set it to load the browser as :
webview.loadurl(urlfield.getText().toString());
webview.requestFocus();
This should load the web browser with the URL that you requested.
Hope this helps... :)