任何更好的通知方式

时间:2014-07-26 18:04:46

标签: android notifications

NotificationCompat.Builder builder = new NotificationCompat.Builder(

                    context).setContentTitle("Recording...")

                    .setContentText("Currently recording")
                    .setAutoCancel(true)
                    .setPriority(NotificationCompat.PRIORITY_DEFAULT)
                    .setWhen(System.currentTimeMillis()).setOngoing(true)
                    .setContentIntent(pendingIntent);

            notificationManager.notify(9999, builder.build());

已编辑的代码,2个问题,PendingIntent和NotificationManager。

1 个答案:

答案 0 :(得分:0)

您可以使用此代码:

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

Intent notificationIntent = new Intent(this, RecordActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
            notificationIntent, 0);

 NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setContentTitle("Title of notification")
            .setContentText("Content title")
            .setAutoCancel(true)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT)
            .setWhen(System.currentTimeMillis())
            .setOngoing(true)
            .setContentIntent(pendingIntent);

notificationManager.notify(9999, builder.build());

取消通知:

notificationManager.cancel(9999);