Android M,NotificationCompat.Builder

时间:2015-11-29 08:34:42

标签: android android-6.0-marshmallow

如何在使用Android M时使用notificationCompate.builder自动隐藏/消除动手通知,我在Android M中使用Nexus Android 6.0(官方)无法自动隐藏/去动手动通知。

这里我的代码我正在使用

private void showNotification(Context context, String number) {

    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    Intent intent = new Intent(context, IncomingCallReceiver.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0);

    NotificationCompat.Builder mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(context.getString(R.string.app_name))
            .setStyle(new NotificationCompat.BigTextStyle().bigText("Incoming number is " + number))
            .setContentText(number)
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
            .setAutoCancel(true)
            .setColor(Color.RED)
            .setContentIntent(contentIntent)
            .setFullScreenIntent(contentIntent, true);

    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

这段代码工作得很好Android 5.1.1

0 个答案:

没有答案