Search code examples
javaandroidbroadcastreceiverandroid-c2dmgoogle-cloud-messaging

list c2dm / GCM registered applications


Is there a way to list all the applications installed on the Android Phone, in order to know if they are registered to a GCM / C2DM account, and will receive datas ?

I actually receive some ads on my phone, and i would like to know wich application is spamming me. I made a few C2DM applications myself, and i know i added those lines in the manifest :

<receiver android:name=".NotificationsReceiver" android:permission="com.google.android.c2dm.permission.SEND">
                 <intent-filter>
                      <action android:name="com.google.android.c2dm.intent.RECEIVE"></action>
                      <action android:name="com.google.android.c2dm.intent.REGISTRATION"></action>
    ...

If we can detect if an application has those lines in its manifest, we should be able to list them.


Solution

  •     PackageManager pm = context.getPackageManager();
        List<PackageInfo> packages = pm.getInstalledPackages(PackageManager.GET_PERMISSIONS);
        for (PackageInfo pi : packages)
        {
            for (String usesPermission : pi.requestedPermissions){
                if (usesPermission.equalsIgnoreCase("com.google.android.c2dm.permission.RECEIVE")){
                    Log.d(TAG, "app with permission to receive push: "+pi.applicationInfo.name);
                }
            }
        }