我一直在試圖弄清楚過去兩個小時;我已經執行了初始化推送通知所需的所有步驟,但我甚至無法收到測試通知。在解析中無法接收推送通知
在我的應用程序的儀表板上,我看到一個名爲「安裝」的類,其中包含用戶的對象ID。
如果我嘗試向所有設備發送推送通知,它會顯示在推送日誌中,但沒有任何設備上註冊。
爲了彌補這個問題,我嘗試卸載並在模擬器中重新安裝應用程序,清理項目,重新啓動android studio並以其他用戶身份登錄(當我發送測試通知時,另一個設備已在安裝類中註冊)。沒有任何工作。我附上了下面的相關代碼。
public class MyApplicationName extends Application {
public static final String TAG = MyApplicationName.class.getSimpleName();
@Override
public void onCreate() {
Parse.initialize(this, "-", "-");
ParseInstallation.getCurrentInstallation().saveInBackground();
}
//To register the installation to each user that logs in
public static void updateParseInstallation(ParseUser user) {
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put(ParseConstants.KEY_USER_ID, user.getObjectId());
installation.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e!= null) {
Log.d(TAG, e.getMessage());
}
}
});
}
}
public class LoginActivity extends Activity {
// some code
if (e == null) {
// login success!
MyApplicationName.updateParseInstallation(user);
// some other code
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!--
IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
to match your app's package name + ".permission.C2D_MESSAGE".
-->
<permission android:protectionLevel="signature"
android:name="Package.Package1.C2D_MESSAGE" />
<uses-permission android:name="Package.Package1.permission.C2D_MESSAGE" />
<application
android:name=".Application"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
//other code
</activity>
<service android:name="com.parse.PushService" />
<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="Package.Package1" />
</intent-filter>
</receiver>
</application>
編輯
我添加了一些額外的代碼,以獲得更多的的形成,添加以下代碼,與所述的logcat的相關部分沿
public class MyApplicationName extends Application {
//code for initializing parse and ParsePush
//this static method will run everytime a user logs in
public static void updateParseInstallation(ParseUser user) {
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put(ParseConstants.KEY_USER_ID, user.getObjectId());
installation.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e!= null) {
Log.d(TAG, e.getMessage());
因此,一旦用戶登錄,下面的代碼運行: MyApplicationName.updateParseInstallation(用戶);
推送通知是假設運行每次對手發現:
protected void sendPushNotification() {
ParseQuery<ParseInstallation> query = ParseInstallation.getQuery();
query.whereMatches(ParseConstants.KEY_USER_ID, mOpponent.getObjectId());
ParsePush push = new ParsePush();
push.setQuery(query);
push.setMessage(getString
(R.string.opponent_found_notification,
ParseUser.getCurrentUser().getUsername()));
push.sendInBackground(new SendCallback() {
@Override
public void done(ParseException e) {
if (e != null) {
Log.d(TAG, e.getMessage());
這裏是logcat的有趣的部分:
09-18 14:32:28.290 2324-2358/com.teamtreehouse.ribbit E/com.parse.ParsePushRouter﹕ Ignoring PPNS push missing timestamp
09-18 14:41:18.580 8824-8831/Package.Package1/W/art﹕ Suspending all threads took: 10ms
09-18 14:47:28.500 2324-2358/com.teamtreehouse.ribbit E/com.parse.ParsePushRouter﹕ Ignoring PPNS push missing timestamp
09-18 15:01:14.660 1314-1350/system_process W/BatteryStatsImpl﹕ Couldn't get kernel wake lock stats
Ribbit的是我在練習發送推送通知的應用在嘗試推送當前的應用程序之前。我不明白爲什麼這個應用程序顯示在日誌中,但我懷疑這是推送通知不起作用的原因。我試圖清理我的瀏覽器,重新啓動android studio,但我在日誌貓中得到相同的消息。有人可以請,請幫我在這裏?我附上了下面的整個日誌貓,以防有人感興趣。
09-18 14:32:28.140 1314-1314/system_process I/ActivityManager﹕ Killing 2301:com.android.exchange/u0a27 (adj 11): empty for 1800s
09-18 14:32:28.150 1314-1314/system_process I/ActivityManager﹕ Killing 2244:com.android.settings/1000 (adj 13): empty for 1804s
09-18 14:32:28.160 1314-1314/system_process I/ActivityManager﹕ Killing 2142:com.android.managedprovisioning/u0a8 (adj 13): empty for 1807s
09-18 14:32:28.170 1314-1314/system_process I/ActivityManager﹕ Killing 2114:com.android.dialer/u0a4 (adj 13): empty for 1807s
09-18 14:32:28.180 1314-1314/system_process I/ActivityManager﹕ Killing 1870:com.android.defcontainer/u0a3 (adj 13): empty for 1808s
09-18 14:32:28.190 1314-1314/system_process I/ActivityManager﹕ Killing 2004:com.android.music/u0a33 (adj 13): empty for 1812s
09-18 14:32:28.290 2324-2358/com.teamtreehouse.ribbit E/com.parse.ParsePushRouter﹕ Ignoring PPNS push missing timestamp
09-18 14:41:18.580 8824-8831/Package.Package1/W/art﹕ Suspending all threads took: 10ms
09-18 14:47:28.500 2324-2358/com.teamtreehouse.ribbit E/com.parse.ParsePushRouter﹕ Ignoring PPNS push missing timestamp
09-18 15:01:14.660 1314-1350/system_process W/BatteryStatsImpl﹕ Couldn't get kernel wake lock stats
09-18 15:02:00.030 1314-1340/system_process I/ProcessStatsService﹕ Prepared write state in 0ms
09-18 15:02:40.080 1314-1314/system_process V/BackupManagerService﹕ Running a backup pass
09-18 15:02:40.100 1314-1458/system_process V/PerformBackupTask﹕ Beginning backup of 7 targets
09-18 15:02:40.120 1556-1841/com.android.inputmethod.latin I/LatinIME:LogUtils﹕ Dictionary info: dictionary = UserHistoryDictionary.en_US ; version = 1441827702 ; date = 1442613760
09-18 15:02:40.160 1314-1458/system_process D/PerformBackupTask﹕ invokeAgentForBackup on @[email protected]
09-18 15:02:40.160 1314-1458/system_process V/BackupServiceBinder﹕ doBackup() invoked
09-18 15:02:40.180 2324-2358/com.teamtreehouse.ribbit E/com.parse.ParsePushRouter﹕ Ignoring PPNS push missing timestamp
09-18 15:02:40.200 1314-1458/system_process I/BackupRestoreController﹕ Getting widget state for user: 0
09-18 15:02:40.200 1314-1458/system_process I/PerformBackupTask﹕ no backup data written; not calling transport
09-18 15:02:40.200 1314-1458/system_process D/PerformBackupTask﹕ starting agent for backup of BackupRequest{pkg=com.android.dialer}
09-18 15:02:40.220 1314年至1458年/ system_process I/ActivityManager:啓動PROC 27097:com.android.dialer/u0a4備份com.android.dialer/.DialerBackupAgent 09-18 15 :02:40.220 1314-1458/system_process D/BackupManagerService:正在等待ApplicationInfo代理{527c6ec com.android.dialer} 09-18 15:02:40.230 27097-27097 /? D/ExtensionsFactory:沒有自定義擴展。
我看着你的答案,我已經採取了,你做的完全一樣的步驟,但無濟於事。 – Frosty619
你好,請看編輯,我提供了新的信息。 – Frosty619