Is it possible to simulate a GCM receive from the adb shell / am command line? I'm getting an error

后端 未结 4 1397
难免孤独
难免孤独 2020-12-30 00:01

I\'m trying to simulate as if the device is receiving a GCM push message by using adb and the command line. I\'ve tried this command to broadcast a GCM intent:



        
4条回答
  •  北荒
    北荒 (楼主)
    2020-12-30 00:34

    Better than temporarily editing AndroidManifest.xml to remove the permission check, and remembering to restore it later, you can automatically disable the permission check in debug builds.

    To do this, set the attribute via a Manifest Merger placeholder:

    
    

    then set the placeholder in build.gradle:

    buildTypes {
        debug {
            ...
            manifestPlaceholders = [gcmPermissionRequired: ""] // "" => let the GCM BroadcastReceiver accept Intents from 'adb shell am broadcast'
        }
        release {
            ...
            manifestPlaceholders = [gcmPermissionRequired: "com.google.android.c2dm.permission.SEND"]
        }
    }
    

    (Note: Previously I used debug & release string resources. It turns out that the Play store rejects the app if it defines an intent filter permission using a string resource.)

提交回复
热议问题