我在我的应用程序中使用解析通知.我正在使用GcmBroadcastReceiver接收通知提醒.但我看到很多通知收到我的应用程序.我想更新状态栏中的通知,所以我使用自定义接收器.当通过GcmBroadcastReceiver接收通知时,我的自定义广播接收器被调用.所以在我的状态栏中同时包含gcm和自定义通知.我只想要自定义通知.如何解决这个问题呢?
清单代码:
android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false" >
android:name="com.packagename.IncomingReceiver"
android:enabled="true"
android:exported="false" >
申请类:
Parse.initialize(this, "app id", "client id");
Incomingreceiver类:
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());
}
}