2017-04-20 3 views
0
public void cancelNotification() 
    { 
     NotificationCompat.Builder builder = new NotificationCompat.Builder(AcceptUserRequest.this); 
     builder.setSmallIcon(R.mipmap.lo); 
     builder.setLargeIcon(BitmapFactory.decodeResource(this.getApplicationContext().getResources(), 
       R.mipmap.peoplehelperlogo)); 

    builder.setContentTitle("PEOPLE HELPER"); 
    builder.setContentText("Accepted request has been cancelled"); 
    builder.setAutoCancel(true); 

    Intent intent = new Intent(AcceptUserRequest.this, BroadcastFragment.class); //creates an explicit intent 
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(AcceptUserRequest.this); 
    stackBuilder.addParentStack(AcceptUserRequest.this); //adds the intent 
    stackBuilder.addNextIntent(intent); //put the intent to the top of the stack 
    PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); //(id, flag) //creates a pending intent 
    builder.setContentIntent(pendingIntent); //adds the PendingIntent to the builder 
    NotificationManager notificationManager = (NotificationManager) AcceptUserRequest.this.getSystemService(Context.NOTIFICATION_SERVICE); 
    notificationManager.notify(0, builder.build()); 
} 

答えて

0

これはダミーコードの一部です。これが役立ちます。

buildNotificationCommon NotificationCompat.Builderプライベート静的に(コンテキスト_context、.....){

NotificationCompat.Builder builder = new NotificationCompat.Builder(_context).setWhen(System.currentTimeMillis()).......; 
//Vibration 
    builder.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 }); 

//LED 
    builder.setLights(Color.RED, 3000, 3000); 

//Ton 
    builder.setSound(Uri.parse("uri://sadfasdfasdf.mp3")); 

return builder; 

}

+0

役立つかもしれませんコードは動作しません。 – LMae

0

それは私が私にそれを挿入しようとしたあなた

NotificationCompat.Builder builder = new  NotificationCompat.Builder(_context).setWhen(System.currentTimeMillis()).......; 
//Vibration  
builder.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 }); 

//LED   
builder.setLights(Color.RED, 3000, 3000); 

//Ton 
builder.setSound(Uri.parse("uri://sadfasdfasdf.mp3")); 

return builder; 
+0

私のコードに挿入しようとしましたが、動作しません。 – LMae

+0

それは解決策を得ることを試みる最も可能性が高いです。 –

+0

builder.setAutoCancel(true)の下に挿入しました。 – LMae

関連する問題