"Pushes sent 0" 在 android 的解析仪表板中
"Pushes sent 0" in parse dashboard for android
我正在尝试将推送通知从 parse 发送到 android。从浏览器发送时,设备的计算会正确显示。但是 "Pushes sent 0" 正在浏览器中显示。
我在应用程序中注册通知class
ParsePush.subscribeInBackground("", new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
ParseInstallation.getCurrentInstallation().saveInBackground();
我还在我的 android 项目中创建了 Receiver
public class PushMessageBroadcast extends ParsePushBroadcastReceiver {
@Override
public void onPushOpen(Context context, Intent intent) {
Log.d("The push","open");
}
@Override
protected Notification getNotification(Context context, Intent intent) {
// TODO Auto-generated method stub
return super.getNotification(context, intent);
}
@Override
protected void onPushDismiss(Context context, Intent intent) {
// TODO Auto-generated method stub
super.onPushDismiss(context, intent);
}
@Override
protected void onPushReceive(Context context, Intent intent) {
//here You can handle push before appearing into status e.g if you want to stop it.
super.onPushReceive(context, intent);
}
}
我也做了清单中的更改:
<receiver
android:name=".receivers.PushMessageBroadcast "
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>
我需要更改解析中的任何设置吗?提前致谢。
已编辑答案
@lochana-tejas 发表评论后,我意识到我的回答不正确,因为我在 Google 开发者控制台 "Cloud Messaging for Android" 中再次禁用,但我的设备无论如何都收到了通知。
所以您需要控制的第一件事是在 Parse Dashboard 中您有 class Installation 和这个 class 注册了一台或多台设备。如果您没有此 class 或为空,“发送的推送”将为 0。
我把我的代码复制到这里所以你可以比较
public static void registerParse(Context context) {
Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
Parse.initialize(context, PARSE_APPLICATION_ID, PARSE_CLIENT_KEY);
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground(PARSE_CHANNEL, new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "Successfully subscribed to Parse!");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
}
//This is the user that will be inserted in "Installation class"
public static void subscribeWithUser(String user) {
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("user", user);
installation.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Log.e("subscribeWithUser", "User subscribed successfully!!", e);
} else {
e.printStackTrace();
Log.e("subscribeWithUser", "Error to save user", e);
}
}
});
}
我的清单是这样的
<!-- Added for Parse push notifications -->
<service android:name="com.parse.PushService" />
<receiver
android:name=".receiver.CustomPushReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<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.parse.starter" />
</intent-filter>
</receiver>
<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>
我正在尝试将推送通知从 parse 发送到 android。从浏览器发送时,设备的计算会正确显示。但是 "Pushes sent 0" 正在浏览器中显示。
我在应用程序中注册通知class
ParsePush.subscribeInBackground("", new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
ParseInstallation.getCurrentInstallation().saveInBackground();
我还在我的 android 项目中创建了 Receiver
public class PushMessageBroadcast extends ParsePushBroadcastReceiver {
@Override
public void onPushOpen(Context context, Intent intent) {
Log.d("The push","open");
}
@Override
protected Notification getNotification(Context context, Intent intent) {
// TODO Auto-generated method stub
return super.getNotification(context, intent);
}
@Override
protected void onPushDismiss(Context context, Intent intent) {
// TODO Auto-generated method stub
super.onPushDismiss(context, intent);
}
@Override
protected void onPushReceive(Context context, Intent intent) {
//here You can handle push before appearing into status e.g if you want to stop it.
super.onPushReceive(context, intent);
}
}
我也做了清单中的更改:
<receiver
android:name=".receivers.PushMessageBroadcast "
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>
我需要更改解析中的任何设置吗?提前致谢。
已编辑答案
@lochana-tejas 发表评论后,我意识到我的回答不正确,因为我在 Google 开发者控制台 "Cloud Messaging for Android" 中再次禁用,但我的设备无论如何都收到了通知。
所以您需要控制的第一件事是在 Parse Dashboard 中您有 class Installation 和这个 class 注册了一台或多台设备。如果您没有此 class 或为空,“发送的推送”将为 0。
我把我的代码复制到这里所以你可以比较
public static void registerParse(Context context) {
Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
Parse.initialize(context, PARSE_APPLICATION_ID, PARSE_CLIENT_KEY);
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground(PARSE_CHANNEL, new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "Successfully subscribed to Parse!");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
}
//This is the user that will be inserted in "Installation class"
public static void subscribeWithUser(String user) {
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("user", user);
installation.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Log.e("subscribeWithUser", "User subscribed successfully!!", e);
} else {
e.printStackTrace();
Log.e("subscribeWithUser", "Error to save user", e);
}
}
});
}
我的清单是这样的
<!-- Added for Parse push notifications -->
<service android:name="com.parse.PushService" />
<receiver
android:name=".receiver.CustomPushReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<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.parse.starter" />
</intent-filter>
</receiver>
<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>