android - 解析安装未获取 DeviceToken

标签 android parse-platform push-notification push android-notifications

我正在尝试在 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/

相关文章:

iOS 推送通知句柄

android - getIntent 错误,未被识别

java - 广播接收器中未触发断点

ios - 从解析加载缓存图像时出现 Buggy UICollectionView

android - 解析推送通知在 Genymotion 中有效,但在真实手机中无效

ios - 为 iOS 推送通知导入 SSL 证书会阻止其他开发人员处理该项目吗?

android - 使用带有 android 的手持式蓝牙打印机

java - ActiveAndroid TypeSerializer - 枚举列表

ios - Facebook iOS SDK : get album's cover picture

javascript - 如何导出服务 worker 中的事件接收的数据以对组件使用react