0

通知を作成し、それをBroadcastReceiverのonReceiverに表示します。しかし、私はそれをすることができません。どうして ? 私のクラスのコードは次のとおりです。なぜ私はBroadcastReceiverのOnReceiverで通知を作成できませんか?

public class AlarmNotificationReceiver extends BroadcastReceiver{ 
//private Intent intent; 
private NotificationManager notificationManager; 
private Notification notification; 
@Override 
public void onReceive(Context context, Intent intent) { 
    // TODO Auto-generated method stub 

    long value1 = intent.getLongExtra("param1", 0);  
    String value2 = intent.getStringExtra("param2"); 
    Toast.makeText(context, "Hello! How r u ?", Toast.LENGTH_SHORT).show(); 
    addTwoMonthNotification(); 

} 

private void addTwoMonthNotification(){ 
    notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); 
    int icon = R.drawable.icon; 
    CharSequence text = "Your amout is due on this date"; 
    CharSequence contentTitle = "Tax Calculator App"; 
    CharSequence contentText = "Your tax amount is due on the "+System.currentTimeMillis()+""; 
    long when = System.currentTimeMillis(); 

    Intent intent = new Intent(this, NotificationViewer.class); 
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0); 
    notification = new Notification(icon,text,when); 

    long[] vibrate = {0,100,200,300}; 
    notification.vibrate = vibrate; 

    notification.ledARGB = Color.RED; 
    notification.ledOffMS = 300; 
    notification.ledOnMS = 300; 

    notification.defaults |= Notification.DEFAULT_LIGHTS; 
    //notification.flags |= Notification.FLAG_SHOW_LIGHTS; 

    notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent); 
    notificationManager.notify(NotificationConstants.NOTIFICATION_ID, notification); 
} 

}

はそれのための溶液を得ました。おかげさまで

答えて

1

あなたはこの見たことがあります:

メイクを:あなたはそう、あなたがまだの場合は、静的に、マニフェストにあなたの受信機を追加する必要がありますContext.registerReceiver()を使用しているようですが、見えない startActivity() from BroadcastReceiver

をあなたはPHONE_STATEがと接続詞で使用することができる意思の一例であり、マニフェスト

以上
<receiver android:name=".AlarmNotificationReceiver"> 
    <intent-filter> 
      <action android:name="android.intent.action.PHONE_STATE" /> 
    </intent-filter> 
</receiver> 

に次のように持っていることを確認

詳細参照:助けhttp://thinkandroid.wordpress.com/2010/02/02/custom-intents-and-broadcasting-with-receivers/

願っています!

関連する問題