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.