2014-06-15 108 views
0

我正嘗試通過其他操作發送通知。我註冊它的服務:來自服務的通知

IntentFilter filter = new IntentFilter(); 
filter.addAction(ACT_ACCEPT); 
receiver = new notifReciever(); 
this.registerReceiver(receiver, filter); 

我的廣播接收器:

public class notifReciever extends BroadcastReceiver { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     Log.d("BR_Action", intent.getAction()); 
    } 
}; 

我送這樣的:用標籤"BR_Action"

PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, 
    new Intent(this, MainActivity.class) 
    .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP), 
    PendingIntent.FLAG_CANCEL_CURRENT); 
PendingIntent contentIntentAccept = PendingIntent.getActivity(getApplicationContext(), 0, 
    new Intent(this, AppService.class).setAction(ACT_ACCEPT), PendingIntent.FLAG_CANCEL_CURRENT); 

n = new Notification.Builder(getApplicationContext()) 
    .setContentTitle("Test") 
    .setContentText(msg) 
    .setSmallIcon(R.drawable.ic_launcher) 
    .setAutoCancel(true) 
    .setVibrate(pattern) 
    .addAction(R.drawable.ic_stat_accept, "Accept", contentIntentAccept) 
    .setStyle(new Notification.BigTextStyle().bigText(msg)) 
    .setContentIntent(contentIntent).build(); 

但串不添加到日誌。

+0

我的答案是否解決了您的問題Alex? – Saket

回答

1

onReceive()只會在您啓動Intent時才被調用,而不是隻註冊它。嘗試使用startActivity(new Intent(ACT_ACCEPT));