What name Google Navigation package name and how to build intent? - android

I'm trying to use PackageManager to detect if Google navigation installed on a phone. If I use "URI = google.navigation" it doesn't find it.
What is the proper name for this package?
Also, I found sample on how to call google navigation with intent but I didn't find how to format full address with Address/city/state/zip. Any samples around?

For the US this works ...
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("google.navigation:q=housenumber+street+city+state+zip+country");
Spaces are ok between the + symbol

Related

Launching Huawei Petal Maps Directions via Intent on Android

Is it possible to launch Huawei Petal Maps with navigation from point A to point B using intent just like in google maps? If yes, how?
Yes, you can use an intent to launch the Petal Map app, and then use navigation functions in the app.
Deep link example:
mapapp://navigation?saddr=xxx&daddr=xxx&language=xx&type=xxx
mapapp://navigation?saddr=home&daddr=company&language=en&type=drive
mapapp://navigation?type=exit
To use this function, you need to set uriString to the following:
"mapapp://navigation?saddr=25.102916,55.165363&daddr=25.164610000000,55.228869000000&language=en&type=drive"
Sample code after modification:
String uriString = "mapapp://navigation?saddr=25.102916,55.165363&daddr=25.164610000000,55.228869000000&language=en&type=drive";
Uri content_url = Uri.parse(uriString);
Intent intent = new Intent(Intent.ACTION_VIEW, content_url);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
For more details, see docs.
As it would seem from this link, India is currently not among the supported regions for Huawei Petal Map. Currently, you would not be able to use it for navigation.

Android Google Translate QuickTranslateActiviy - Intent extra issue

I want to use the QuickTranslateActiviy
and I have tried this
Intent i = new Intent();
i.setAction(Intent.ACTION_PROCESS_TEXT);
i.addCategory(Intent.CATEGORY_DEFAULT);
i.putExtra(Intent.EXTRA_TEXT,"String");
i.setType(ClipDescription.MIMETYPE_TEXT_PLAIN);
i.setComponent(new ComponentName("com.google.android.apps.translate","com.google.android.apps.translate.QuickTranslateActivity"));
startActivity(i);
and It just keep showing the toast that could not find text.
But the manifest of the Google translate here show that it accept plain text
had anyone try that before?Or am I doing it in a wrong way?
Tactically, you are using the wrong extra name. It should be EXTRA_PROCESS_TEXT or EXTRA_PROCESS_TEXT_READONLY, not EXTRA_TEXT.
Strategically, your implementation will break any time that the Google Translate app refactors their code or otherwise changes the fully-qualified class name of the activity.

How can I open Sonos controller with search string

Is is possible to open the Sonos android Controller passing for example a search query that the controller will process and display results for?
For example:
Intent i = getPackageManager().getLaunchIntentForPackage("com.sonos.acr");
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setData(Uri.parse("artist:The%20Doors"));
startActivity(i);
We don't support this today. I will bring this up with the team as a possible future feature.

How to show 'Clear Defaults' programmatically?

Now i am working on a Home Launcher application.I want to clear defaults of default home launcher(eg: Samsung Home). ie.I want to show Settings-> Applications->Manage Application->Samsung Home->clear defaults programmatically.
How to show this through code?
Thanks in Advance
NOTE: Since this question is limited to accessing the Manage Application Settings options, my answer covers just that. You will have to figure out a way of getting the actual Package Name.
Also, if the idea is to also Clear the Defaults automatically via code, then that, to the best of my knowledge, cannot be done. Someone can correct me if I am wrong on this.
That being said, this piece of code will open the specific application's Manage Application screen from your app (the package name must be supplied).
Intent showSettings = new Intent();
showSettings.setAction(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uriAppSettings = Uri.fromParts("package", "THE_APP_PACKAGE_NAME", null);
showSettings.setData(uriAppSettings);
startActivity(showSettings);
For example, if the package name of the Google Maps application is com.google.android.apps.maps, the replace THE_APP_PACKAGE_NAME with it and the code will open the Manage Application screen for the Google Maps application.
UPDATE:
The PackageManager has a method, clearPackagePreferredActivities used to clear the default via code. However, that doesn't seem to work in newer Android versions: https://stackoverflow.com/a/10246711/450534
Other posts worth reading:
https://stackoverflow.com/a/7750187/450534
https://groups.google.com/forum/?fromgroups=#!topic/android-developers/Rzv8VU-EUAw
Just for complete the picture, for getting "THE_APP_PACKAGE_NAME" youc can use something like that :
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
ResolveInfo resolveInfo = getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
String packageName = resolveInfo.activityInfo.packageName;

Android: starting a default application or one which may be different on different devices

I would like to start a default application: browser, contact-book, phone, email, music app, etc. I have found many q/a, like browser opening a specific URL or blank, and here the answer is even "No not possible". But I would like to just open/launch it without telling it to go to a specific URL or sending a mail to someone, etc.
However, I also saw some Home applications where this seems to be working (at least for some apps). On my colleague's device there is for example a different contact-book (no google) which is detected and opened correctly.
I have seen in the Android documentation some intent categories that point to these problems, but these are only >= API.11. So I can't use/test them on my device.
Question: Is it not somehow possible to launch a default application (having the app chooser is of course ok) without providing extra data? If no, what do you think are these Home apps doing (perhaps workarounds are somehow possible).
PS: for the phone app I think, I have a workaround using Intent.ACTION_DIAL without any other information which will open simply the dialer.
UPDATE: I modified the title. Some applications like the address book may not be the same on different devices. So in this case I would like to start the address-book app, whichever this is.
This answer is not a 100% answer, but some workarounds on some typical applications.
Still open are: music player, address book
Browser: I get a list of applications that handle "http"-data intents, and then I look if one is available in the list of preferred applications.
Intent appFilter = new Intent(Intent.ACTION_VIEW);
appFilter.setData(Uri.parse("http://www.google.com"));
List<ResolveInfo> browserInfoList = pm.queryIntentActivities(appFilter, 0);
List<IntentFilter> outFilters = new ArrayList<IntentFilter>();
List<ComponentName> outActivities = new ArrayList<ComponentName>();
pm.getPreferredActivities(outFilters, outActivities, null);
if(outActivities.size() > 0) {
for(ComponentName cn : outActivities) {
String cnClass = cn.getClassName();
String cnPkg = cn.getPackageName();
for (ResolveInfo info : browserInfoList) {
if(info.activityInfo.name.equals(cnClass) &&
info.activityInfo.packageName.equals(cnPkg)) {
return cn;
}
}
}
}
In case no default is found, I open a browser chooser dialog, see here.
Phone: as described in the question:
Intent intent = new Intent(Intent.ACTION_DIAL);
startActivity(intent);
You can start apps by the function "startActivity" if you know about the canonical app name
like "android.com.browser". Do this simple by searching for AndroidManifest.xml in the app
source code (look at Codeaurora.com or at github/Cyanogenmod) and grab the app name you want.
After you know about the App name ("Activity") implement the code as follows:
Intent intent = new Intent();
intent.setClassName(this, "com.android.browser");
intent.setCategory(Intent.ACTION_MAIN);
startActivity(intent);
THIS is only a example, sometimes you have to put intent extras or data values, this information can be found in the app's AndroidManifest.xml too.

Categories

Resources