parse.com - 从android上的状态栏中删除特定通知

时间:2015-09-01 10:51:20

标签: android parse-platform push

我想从android状态栏中删除一个具有以下功能的特定通知:cancel()。

为此我需要通知ID。

如何从parse.com通知中获取此ID?

1 个答案:

答案 0 :(得分:0)

好的,这将需要一些实验。基本上你需要一个BroadCaster Parse的自定义类。因此,您需要扩展它并创建自己的自定义类,以便处理自定义事件,例如使用通知构建器发出通知

编辑:替换整个代码。这很有效。

  public class MyCustomReceiver extends ParsePushBroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        super.onReceive(context, intent);
        String payload=intent.getExtras().toString();

        Log.d("PARSEPUSH", payload);
        Intent notificationIntent = new Intent(context, MainActivity.class);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        PendingIntent piIntent=PendingIntent.getActivity(context,0,
                notificationIntent,0);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                .setContentTitle("My Notification").setSmallIcon(android.R.drawable.star_on)
                .setContentText("Message Body").setAutoCancel(true);
        mBuilder.setContentIntent(piIntent);

        Notification pnNotif = mBuilder.build();

        Integer notificationId=0;

        NotificationManager mNotificationManager = (NotificationManager)
                context.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(notificationId, pnNotif);  // Set notification ID

    }

    @Override
    protected void onPushReceive(Context context, Intent intent) {
        super.onPushReceive(context, intent);
    }

    public MyCustomReceiver() {
        super();
    }

    @Override
    protected Notification getNotification(Context context, Intent intent) {
    return null;
    }
}

确保更新清单并将ParsePushBroadcastReveiver替换为MyCustomReceiver。

相关问题