Cannot launch what 3 words intent - android

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

Related

Installed app doesn't open intent

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?

Cannot start Settings$UserSettingsActivity

I have an application that displays all activities of all apps. It displayed the MultiUser Settings activity as
com.android.settings.Settings$UserSettingsActivity
Clicking on the above shortcut from this app launches the regular multiuser settings activity. But when I try to start the same activity from am or other ways like application intent, it fails to start.
I tried from adb,
am start com.android.settings.Settings$UserSettingsActivity
and the result log is
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] pkg=com.android.settings.Settings }
Error: Activity not started, unable to resolve Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.android.settings.Settings }
I also tried to start it from application intent like,
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.android.settings.Settings", "com.android.settings.Settings.UserSettingsActivity"));
startActivity(intent);
Still it doesn't work.
My android device version is 5.1.1 lollipop.
Please help.
When you use the following command:
am start com.android.settings.Settings$UserSettingsActivity
adb takes com.android.settings.Settings$UserSettingsActivity as a package name and tries to find a launch Intent for that package, which fails (because com.android.settings.Settings$UserSettingsActivity is not a package name.
If you want to launch a specific component, the syntax is:
am start com.android.settings/com.android.settings.Settings$UserSettingsActivity
You need to specify the package name and the class name separated by "/"
When you do this in code:
intent.setComponent(new ComponentName("com.android.settings.Settings", "com.android.settings.Settings.UserSettingsActivity"));
you are passing the wrong arguments to the ComponentName constructor. The constructor takes 2 arguments: package name and class name. This needs to be like this:
intent.setComponent(new ComponentName("com.android.settings", "com.android.settings.Settings$UserSettingsActivity"));
The package name is "com.android.settings" and the class name is "com.android.settings.Settings$UserSettingsActivity" which is an inner class of "com.android.settings.Settings".

Launch Chrome from Android app but point to local content

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 }

Open Intent in a new context

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.

Android call OEM activity by component name

On a Huwaie Ascend, when we walk through the settings menu:
Settings -> SD card & phone storage -> Software Upgrade -> SD card Upgrade
We are then brought to a screen where the user can upgrade.
And then using adb logcat we see this:
Starting activity: Intent { act=android.intent.action.MAIN cmp=com.android.settings/.SystemUpgradeCheck }
We can use adb to simulate this by calling:
adb shell am start -n com.android.settings/.SystemUpgradeCheck
This is successful, and we see the screen.
However, when we try to call this from within an activity like this:
Intent i = new Intent(Intent.ACTION_MAIN);
i.setComponent(new ComponentName("com.android.settings", ".SystemUpgradeCheck"));
startActivity(i);
We get this error:
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.settings/.SystemUpgradeCheck}; have you declared this activity in your AndroidManifest.xml?
What can we do to overcome this? Am I calling the intent wrong?
Figured it out :)
Context foreignContext = createPackageContext("com.android.settings", Context.CONTEXT_IGNORE_SECURITY | Context.CONTEXT_INCLUDE_CODE);
Class<?> yourClass = foreignContext.getClassLoader().loadClass("com.android.settings.SystemUpgradeCheck");
Intent intent = new Intent(foreignContext, yourClass);
startActivity(intent);

Categories

Resources