Android 无法在解析中接收推送通知
在过去的两个小时里,我一直在想这个问题;我已经执行了初始化推送通知所需的所有步骤,但我甚至无法接收测试通知 在我的应用程序的仪表板上,我确实看到一个名为“Installation”的类,其中包含用户的对象Id 如果我尝试向所有设备发送推送通知,它会显示在推送日志中,但设备上没有任何注册 为了解决这个问题,我尝试在emulator中卸载并重新安装应用程序,清理项目,重新启动android studio,并以其他用户的身份登录(当我发送测试通知时,另一个设备已注册到安装类中)。什么都没起作用。我在下面附上相关代码Android 无法在解析中接收推送通知,android,parse-platform,push-notification,Android,Parse Platform,Push Notification,在过去的两个小时里,我一直在想这个问题;我已经执行了初始化推送通知所需的所有步骤,但我甚至无法接收测试通知 在我的应用程序的仪表板上,我确实看到一个名为“Installation”的类,其中包含用户的对象Id 如果我尝试向所有设备发送推送通知,它会显示在推送日志中,但设备上没有任何注册 为了解决这个问题,我尝试在emulator中卸载并重新安装应用程序,清理项目,重新启动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());
}
}
});
}
}
因此,一旦用户登录,就会运行以下代码:
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());
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 @pm@
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/系统/流程I/活动管理器﹕ 启动程序27097:com.android.dialer/u0a4以备份com.android.dialer/.DialerBackupAgent
09-18 15:02:40.220 1314-1458/系统/过程D/备份管理服务﹕ 正在等待ApplicationInfo{527c6ec com.android.dialer}的代理
09-18 15:02:40.230 27097-27097/? D/扩展工厂﹕ 没有自定义扩展。这可能会对您有所帮助
只要避开gradle,看看接收者和清单文件。看看问题。这是我写的一个问题。从问题中复制我在那里使用的代码,并遵循已接受答案上的说明(也是由我提供的)
ParseApplication.java:
package your.package.name;
public class ParseApplication extends Application {
@Override
public void onCreate() {
Parse.initialize(this, "", "");
}
}
我看了你的答案,我已经采取了与你完全相同的步骤,但没有效果。您好,请查看编辑,我提供了新信息。
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());
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 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 @pm@
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}
package your.package.name;
public class ParseApplication extends Application {
@Override
public void onCreate() {
Parse.initialize(this, "", "");
}
}