这是我在 Parse Console 上的安装页面中的情况:
如您所见,有些设备有“deviceToken”,有些没有“deviceToken”。 这不好,因为每个设备都应该有 deviceToken 才能工作。
这怎么可能?这是一个严重的问题,因为没有 deviceToken 的人不会收到推送通知!
我已按照 Parse.com 上的所有说明执行所有操作,即使借助他们的空白项目和网络上的各种问题也是如此。但是没有什么能解决我的问题,现在我什么也做不了。
我唯一能想到的是,在我的应用程序(它已经在商店中)使用 Google Cloud Messaging 之前,我决定通过这个新的更新来更改系统并使用 Parse 完全删除 GCM 系统。这两个系统之间可能存在冲突吗?
我需要修复这个问题,你可以想象这是一个严重的错误,现在我 3/4 的用户没有收到推送通知。
如果您下载并安装应用程序:一切正常,deviceToken 没问题。如果您因为设备上已经有 GCM 版本而更新应用:
- 部分设备在 Parse 中注册良好,没有任何问题
- 一些设备在 Parse 中注册,但没有 deviceToken
对于没有 deviceToken 的设备,我尝试了很多方法:手动插入 deviceToken,卸载并重新安装应用程序,删除 Parse 上的特定行等。但没什么好...仍然面临这个问题。
我的代码
Application.java
public class Application extends android.app.Application {
public Application() {
}
@Override
public void onCreate() {
super.onCreate();
// Initialize the Parse SDK.
Parse.initialize(this, "x", "x");
// Specify an Activity to handle all pushes by default.
PushService.setDefaultPushCallback(this, MainActivity.class);
}
}
MainActivity.java 在我的 mainActivity 中,我只是将 deviceToken(在我的情况下是 installationId)连接到我的 userAgent 中:这工作正常:我总是有 installationId 没有任何问题!这是我在 MainActivity 中唯一要做的事情(我还需要做其他事情吗?saveInBackground、回调等等?)
deviceToken = ParseInstallation.getCurrentInstallation().getInstallationId();
webSettings.setUserAgentString(userAgent + " ||" + deviceToken);
AndroidManifest.xml
<!-- Gestione del guasto-->
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- Utilizzo di internet -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Permesso di vibrare per le push notifications -->
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Mantiene attivo il processore così da poter ricevere in qualsiasi momento le notifiche -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Consente di impostare l'allarme per l'aggiornamento automatico -->
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
<permission android:name="com.hoxell.hoxellbrowser.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.hoxell.hoxellbrowser.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application
android:name="com.hoxell.hoxellbrowser.Application"
android:allowBackup="true"
android:icon="@drawable/ic_launcher_hoxell"
android:label="@string/app_name"
android:theme="@style/AppTheme"
>
<!-- Richiesto per le applicazioni che usano Google Play Services -->
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SettingsActivity"></activity>
<receiver android:name=".AlarmReceiver"/>
<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.hoxell.hoxellbrowser.Receiver"
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" />
<category android:name="com.hoxell.hoxellbrowser" />
</intent-filter>
</receiver>
</application>
Build.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// You must install or update the Support Repository through the SDK manager to use this dependency.
compile 'com.android.support:support-v4:20.+' //support
compile "com.google.android.gms:play-services:5.0.+" //play services
compile 'com.parse.bolts:bolts-android:1.+'
compile fileTree(dir: 'libs', include: 'Parse-*.jar')
}
我真的不知道还能做什么,这就是为什么我希望有人可以帮助我。
谢谢。
最佳答案
您是否在平板电脑上同时使用 2 个用户配置文件?因为我遇到了完全相同的问题,并且根据我的经验,配置文件之间存在冲突。事实上,在我的情况下,一台设备将 2 行注册到 Parse 数据库中。一个带有 deviceToken,一个带有“未定义”的 deviceToken。
不幸的是我从来没有解决过这个问题,我猜这是 Parse 的一个错误。
关于android - 解析 : Push Notifications "deviceToken" undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28449777/