Đang sử dụng thông báo phân tích cú pháp trong ứng dụng của tôi. Đang nhận cảnh báo thông báo bằng cách sử dụng GcmBroadcastReceiver. Nhưng tôi thấy rất nhiều thông báo nhận được từ ứng dụng của mình. Tôi nghĩ rằng để cập nhật thông báo trong thanh trạng thái vì vậy tôi đã sử dụng máy thu tùy chỉnh. Khi nhận được thông báo thông qua GcmBroadcastReceiver, người phát sóng tùy chỉnh của tôi đã gọi. Vì vậy, trong thanh trạng thái của tôi có cả thông báo gcm và tùy chỉnh. Tôi chỉ muốn thông báo tùy chỉnh. Làm thế nào để giải quyết vấn đề này?Nhận thông báo Phân tích cú pháp bằng cách sử dụng công cụ phát sóng tùy chỉnh
đang Manifest:
<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.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.tutorials.pushnotifications" to match your app's package name. -->
<category android:name="com.packagename" />
</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.packagename.IncomingReceiver"
android:enabled="true"
android:exported="false" >
<intent-filter>
<action android:name="com.packagename.UPDATE_STATUS" />
</intent-filter>
</receiver>
lớp Application:
Parse.initialize(this, "app id", "client id");
Incomingreceiver lớp:
public class IncomingReceiver extends BroadcastReceiver {
private static final int NOTIFICATION_ID = 1;
public static int numMessages = 0;
@Override
public void onReceive(Context context, Intent intent) {
try {
String action = intent.getAction();
JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
if (action.equalsIgnoreCase("com.packagename.UPDATE_STATUS")) {
String title = "appname";
if (json.has("header"))
title = json.getString("header");
generateNotification(context, title, json,contenttext);
}
} catch (JSONException e) {
Log.d("jsonexc", "JSONException: " + e.getMessage());
}
}
private void generateNotification(Context context, String title, JSONObject json, String contenttext) {
Intent intent = new Intent(context, NewActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0);
NotificationManager mNotifM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.app_icon).setContentTitle(title).setContentText("contenttext").setNumber(++numMessages);
mBuilder.setContentIntent(contentIntent);
mNotifM.notify(NOTIFICATION_ID, mBuilder.build());
}
}
Xin vui lòng gửi mã mà u sử dụng – Siva
@Gayathiri mã được cập nhật? – Erum
bản sao có thể có của [SDK phân tích cú pháp triển khai BroadcastReceiver tùy chỉnh cho thông báo đẩy trong Android] (http://stackoverflow.com/questions/29657757/parse-sdk-implement-custom-broadcastreceiver-for-push-notifications-in-android) – Cristik