support gmaps v7.6.1+ labeled marker geo intent

This commit is contained in:
Philipp Schaefer 2014-02-17 13:40:37 +01:00
parent 9b5adb9ab9
commit c18cdc4d39
2 changed files with 24 additions and 2 deletions

View File

@ -86,6 +86,14 @@ public class IntentListView extends ListView {
} }
} }
private static final HashSet<String> GEOLABEL_WHITELIST = new HashSet<String>();
static {
if (GEOLABEL_WHITELIST.isEmpty()) {
GEOLABEL_WHITELIST.add("com.google.android.apps.maps");
}
}
private HashMap<ComponentName, Intent> mActivities = new HashMap<ComponentName, Intent>(); private HashMap<ComponentName, Intent> mActivities = new HashMap<ComponentName, Intent>();
private IntentAdapter mAdapter; private IntentAdapter mAdapter;
@ -164,6 +172,16 @@ public class IntentListView extends ListView {
ResolveInfo info = activityList.get(i); ResolveInfo info = activityList.get(i);
ActivityInfo activity = info.activityInfo; ActivityInfo activity = info.activityInfo;
// remove all apps that don't support a geo intent like geo:0,0?q=lat,lng(label)
// they'll receive a default geo intent like geo:lat,lng
if (intent.getData() != null &&
"geo:0,0?q=".regionMatches(false, 0, intent.getData().toString(), 0, 10) &&
!GEOLABEL_WHITELIST.contains(activity.packageName)) {
activityList.remove(i);
i--;
continue;
}
// fix bug in PackageManager - a replaced package name might cause non-exported intents to appear // fix bug in PackageManager - a replaced package name might cause non-exported intents to appear
if (!activity.exported && !activity.packageName.equals(packageName)) { if (!activity.exported && !activity.packageName.equals(packageName)) {
activityList.remove(i); activityList.remove(i);

View File

@ -66,13 +66,17 @@ public class ShareActivity extends FragmentActivity implements ActionBar.TabList
private void setupIntents() { private void setupIntents() {
setupShareIntent(getUrl()); setupShareIntent(getUrl());
// we merge gmaps intents with geo intents since it is not possible // gmaps supports labeled markers via geo intent...most other navigation apps don't
// anymore to set a labeled marker on geo intents // so provide two different geo intents and filter them in IntentListView
ArrayList<Intent> intents = new ArrayList<Intent>(); ArrayList<Intent> intents = new ArrayList<Intent>();
String gMapsUri; String gMapsUri;
try { try {
/*
* doesn't work anymore since gmaps v7.6.1
gMapsUri = "http://maps.google.com/?q=loc:" + mLl gMapsUri = "http://maps.google.com/?q=loc:" + mLl
+ "%20(" + URLEncoder.encode(mTitle, "UTF-8") + ")&z=" + mZoom; + "%20(" + URLEncoder.encode(mTitle, "UTF-8") + ")&z=" + mZoom;
*/
gMapsUri = "geo:0,0?q=" + mLl + "%20(" + URLEncoder.encode(mTitle, "UTF-8") + ")";
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
gMapsUri = "http://maps.google.com/?ll=" + mLl + "&z=" + mZoom; gMapsUri = "http://maps.google.com/?ll=" + mLl + "&z=" + mZoom;
Log.w(e); Log.w(e);