2016-04-06 6 views
0

まず、スタックオーバーフローで言及されたすべての回答を試しましたが、私のアプリケーションではうまくいきませんでした。それは簡単ですが、ワーキング。 私はこれで私を助けるためにあなたに私のコードを共有するのを見た。 私はAPI 22で走っています。通知イベントのテキストと画像をクリックイベントの別のアクティビティに渡す

これはactivityで、通知からテキストを受け取るためにtextViewが含まれています。

public class EventDetails extends AppCompatActivity { 
public static TextView txtDet; 
public String strdet; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    onNewIntent(getIntent()); 
    setContentView(R.layout.activity_event_details); 
    txtDet = (TextView) findViewById(R.id.txtDetail); 
    Intent MyIntent = getIntent(); 
    strdet = MyIntent.getStringExtra("txtDetails"); 

    txtDet.setText(strdet); 



} 

私は、カレンダーの日付をクリックすると、それがうまく機能しているときにテキストを渡すためにgetStringExtraを使用し、私は通知テキストを受信するために同じtextViewを使用したい、私は別のtextViewを使用して問題を持っていけない、との私は同じ通知を受け取るたびに別のimageを受信したいと考えています。

、これは通知activityが、私はAlertReceiver

public class AlertReceiver extends BroadcastReceiver { 


    @Override 
    public void onReceive(Context context, Intent intent) { 


     int notificationId = intent.getIntExtra("id", -1); 
     switch(notificationId){ 
      case 1: 
       createNotification(context, "title1", "event1", "event of today"); 
       break; 
      case 2: 
       createNotification(context, "title2", "event2", "event of today"); 
       break; 
      case 3: 
       createNotification(context, "title3", "event3", "event of today"); 
       break; 
      case 4: 
       createNotification(context, "title4", "event4", "event of today"); 
       break; 
     } 


      } 

    public void createNotification(Context context, String msg, String msgText,String msgAlert){ 

     PendingIntent notificIntent = PendingIntent.getActivity(context, 0, new Intent(context, EventDetails.class), 0); 

     NotificationCompat.Builder mBuilder=new NotificationCompat.Builder(context) 
       .setSmallIcon(R.drawable.not) 
       .setContentTitle(msg) 
       .setTicker(msgAlert) 
       .setContentText(msgText); 
     //intent to fire when notification clicked on 
     mBuilder.setContentIntent(notificIntent); 
     //how the person will be notified 
     mBuilder.setDefaults(NotificationCompat.DEFAULT_SOUND); 
     //cancel notification when clicked in the taskbar 
     mBuilder.setAutoCancel(true); 
     NotificationManager mNotificationManager= (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE); 

      mNotificationManager.notify(0, mBuilder.build()); 




    } 
} 

任意の提案という名前ですか?

答えて

1

内部作成通知メソッドは、インテントにデータを追加します。どのアクティビティを呼び出すべきかを通知のクリックで指定しただけです。このよう

PendingIntent notificIntent = PendingIntent.getActivity(context, 0, 
     new Intent(context, EventDetails.class).putExtra("txtDetails", yourMsg), 0); 
+0

はYES、これは私だけで編集したputStringExtraは、どのような画像についてputExtra – zyz82

+0

にも、私が今働いている正確にどのように意図理解、おかげでたくさん、私の問題を解決し、しかし?私は、.setSmallIcon(R.drawable.not) – zyz82

関連する問題