2014-07-26 48 views
-1
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。任何更好的通知方式

回答

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); 
+0

見編輯的代碼,我有兩個問題 - 1 - 的PendingIntent不能被解析爲一個變量 - 2 - notificationManager無法解析 – DAVIDBALAS1

+0

節省您的源代碼以創建PendingIntent和NotificationManager實例。 – Joseph

相關問題