我们正在使用firebase云消息来获取推送通知到android应用程序中。
目前,为了测试推送通知,我们需要将消息发送到FCM服务器,并等待消息到达设备。大部分时间设备需要很长时间才能收到来自FCM服务器的通知。
我可以在下面看到一些链接,它们解释了使用adb广播命令向设备发送推送通知(这个示例解释了使用GCM框架发送消息,但我们使用FCM) Is it possible to simulate a GCM receive from the adb shell / am command line? I'm getting an error。
有没有类似的方式使用adb向有FCM的设备发送推送通知?
发布于 2020-03-02 14:48:45
通过adb发送有效载荷是可能的。
虽然权限com.google.android.c2dm.permission.SEND
确实是个问题,但还是有解决办法的。
gradle将FirebaseInstanceIdReceiver
添加到合并的清单中。解决方法是将自己的拷贝添加到清单中,并使用tools:replace="android:permission"
和android:permission="@null"
覆盖权限
<receiver
android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
android:exported="true"
android:permission="@null"
tools:replace="android:permission">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="your.package.name" />
</intent-filter>
</receiver>
然后发出
通过终端的adb shell "am broadcast -n your.package.name/com.google.firebase.iid.FirebaseInstanceIdReceiver -c your.package.name -a com.google.android.c2dm.intent.RECEIVE ...
(PS -我强烈建议只在调试版本中使用gradle的清单占位符或在调试/开发版本中使用单独的AndroidManifest.xml )
发布于 2018-08-17 23:13:26
它适用于我在模拟器上的工作(您既不需要服务器密钥也不需要客户端令牌)。
在AS终端上运行以下命令:
adb root
/com.google.firebase.iid.FirebaseInstanceIdReceiver为了获得广播权限其中,--es
字段与data
节点中的字段相对应:
{
"data": {
"title": "Title",
"body": "Body"
},
"to" : ""
}
发布于 2019-03-11 03:59:33
无法从adb命令发送推送通知。因此您的进程需要以下权限才能通过adb发送广播。但谷歌不允许设置com.google.android.c2dm.permission.SEND
权限。
If you run below command and try to grant send permission to your package.
./adb shell pm grant com.example.hunted "com.google.android.c2dm.permission.SEND"
您将得到以下异常
操作eration not allowed: java.lang.SecurityException: Package com.example.hunted has not requested permission com.google.android.c2dm.permission.SEND
即使您将此权限添加到您的包中
./adb shell pm grant com.example.hunted com.google.android.c2dm.permission.SEND
Operation not allowed: java.lang.SecurityException: Permission com.google.android.c2dm.permission.SEND is not a changeable permission type.
最后当你用adb发送广播时。您将得到以下异常。
BroadcastQueue: Permission Denial: broadcasting Intent { flg=0x400010 cmp=com.example.hunted/com.google.firebase.iid.FirebaseInstanceIdReceiver (has extras) } from null (pid=32279, uid=2000) requires com.google.android.c2dm.permission.SEND due to receiver com.example.hunted/com.google.firebase.iid.FirebaseInstanceIdReceiver
https://stackoverflow.com/questions/40289999
复制相似问题