From my app I want to run Hangouts and from that app users can create video calls.
But on some target devices users have native Google Talk app (not updated to Hangouts).
The problem is: Google Talk and Hangouts - this is the same apps with the identical package name com.google.android.talk
, and I don't know how distinguish them.
My logic: when I found package on device - I just run app. If no - open market page with this app.
Maybe someone knows, how distinguish hangout from google talk app?
My code:
public void startApplication(String packageName){
try
{
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
List<ResolveInfo> resolveInfoList = getPackageManager().queryIntentActivities(intent, 0);
for(ResolveInfo info : resolveInfoList)
if(info.activityInfo.packageName.equalsIgnoreCase(packageName))
{
launchComponent(info.activityInfo.packageName, info.activityInfo.name);
return;
}
showInMarket(packageName);
}
catch (Exception e)
{
showInMarket(packageName);
}
}
private void launchComponent(String packageName, String name){
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
intent.setComponent(new ComponentName(packageName, name));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
private void showInMarket(String packageName){
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
UPD
Now I have only one idea: to check if the publicSourceDir
is /system/app/Talk.apk
- if "yes" - we have preset "Google Talk" app - but I don't think this is good solution.
What do you thing about it?
String publicSourceDir = getPackageManager()
.getPackageInfo(info.activityInfo.packageName, 0).applicationInfo.publicSourceDir;
if(!publicSourceDir.toLowerCase().endsWith(GOOGLE_HANGOUT_SYSTEM_APK.toLowerCase())){
......
}
Checking for installation path stopped working when Google started shipping devices with hangouts installed into the ROM part. I guess the original Nexus 5 ROM includes the new hangouts app in the ROM. Further updates will be installed in user space.
Anyway, checking for permission android.permission.SEND_SMS
should do the trick.
I don't have any device with good old Google Talk to test. But I guess it does not have this permission.
private boolean isHangoutsInstalled(final Context context) {
PackageManager pm = context.getPackageManager();
assert pm != null;
// check for bable aka hangouts app
try {
if (pm.getApplicationInfo("com.google.android.apps.babel", 0) != null) {
return true;
}
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "babel not found, check for talk app");
}
// check for talk app or updated talk app now known as hangouts
try {
if (pm.getApplicationInfo("com.google.android.talk", 0) == null) {
// no talk, no update
return false;
}
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "talk app not found");
// no talk, no update
return false;
}
// talk app found
// check for talk update
return PackageManager.PERMISSION_GRANTED == pm
.checkPermission("android.permission.SEND_SMS",
"com.google.android.talk");
}
I'm not sure with the first part checking for com.google.android.apps.babel
package.
The decoded AndroidManifest.xml
of my N4's hangouts app shows a packageName="com.google.android.apps.babel"
. But the PackageManager
throws a NameNotFoundException
.
Maybe you can just drop that first part completely.