gpt4 book ai didi

android - 解析安装未获取 DeviceToken

转载 作者:行者123 更新时间:2023-11-29 15:11:01 24 4
gpt4 key购买 nike

我正在尝试在 android 中使用解析来推送通知,我在 Application 类中注册解析,如下所示:

@Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, "***************", "***************");
}

我在主要 Activity 中订阅这样的推送:

@Override
protected void onCreate(Bundle savedInstanceState) {

ParsePush.subscribeInBackground("", new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {

ParseInstallation.getCurrentInstallation().saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {


if (e == null) {
String deviceToken = (String) ParseInstallation.getCurrentInstallation().get("deviceToken");
Log.e("MainActivity", "device toekn " + deviceToken);

} else {
Log.e("MainActivity", "failed to subscribe for push " + e.getLocalizedMessage());
}
}
});

} else {
Log.e("MainActivity", "failed to subscribe for push", e);
}
}
});



super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

这是我的 list 部分,适用于解析:

  <service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />

<!--
IMPORTANT: Change "com.parse.starter" to match your app's package name.
-->
<category android:name="com.****" />
</intent-filter>
</receiver>

但是,设备 token 大多数时候返回 null,并且设备在解析仪表板中没有设备 token ,因此,我的设备没有收到推送通知。

奇怪的是,有时它确实有效,我确实获得了 deviceToken 并且安装对象确实获得了推送,有人遇到过这种行为吗?

最佳答案

这个问题最终解决了,简单的错误是标签中manifest的标签中的Application name。由于我在此处发布的代码是“com.***”,因此无人能提供帮助,我深表歉意。

关于android - 解析安装未获取 DeviceToken,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31456351/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com