android定义广播接收器,android – 使用自定义广播接收器接收解析通知

我在我的应用程序中使用解析通知.我正在使用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());

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值