0

以下に、2 つの通知のコードを示します。意図的に、key1andでエクストラを渡していますkey2が、NotificationPillDescription.classgetExtras を使用して key1 しか取得できません。

// 最初の通知の通知コード

Notification notification = new Notification(R.drawable.ic_launcher, "Take your morning pill!", System.currentTimeMillis());
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notifyIntent = new Intent(getApplicationContext(), NotificationPillDescription.class);
    Bundle extras = new Bundle();
    extras.putString("Key1", String.valueOf(1));
    notifyIntent.putExtras(extras);

    contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notifyIntent, 0);
    notification.setLatestEventInfo(this, "Take your Morning pill!", "My Drug", contentIntent);
                        notificationManager.notify(dataProvider.notificationId++, notification);

// 2 回目の通知の通知コード

notifyIntent = new Intent(getApplicationContext(), NotificationPillDescription.class);
        Bundle extras = new Bundle();
        extras.putString("Key2", String.valueOf(2));
        notifyIntent.putExtras(extras);

        contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notifyIntent, 0);
        notification.setLatestEventInfo(this, "Take your Morning pill!", "My Drug", contentIntent);
                            notificationManager.notify(dataProvider.notificationId++, notification);

//NotificationPillDescription.class のコード

Bundle extras = getIntent().getExtras();
            if(extras != null){
                if(extras.containsKey(String.valueOf(1)))
                {
                   Log.d("Pill Id0",extras.getString(String.valueOf(1)) );

                }
                else
                {
                    Log.d("Pill Id1",extras.getString(String.valueOf(2)) );
                }
            }               
4

2 に答える 2

0

そのはず、

extras.getString("Key1")extras.getString("Key2")

それ以外の

extras.getString(String.valueOf(1))&&extras.getString(String.valueOf(2))

于 2012-09-27T05:09:14.883 に答える
0

こちらをご覧ください。バンドルを渡す方法について説明します。あなたの extras.getstring では不十分かもしれません。putextras を使用している場合は、バンドルを宣言する必要がない場合もあります。

ここ:

startActivity() でバンドルを渡しますか?

これも役立つかもしれません:

putExtras 複数の putString が機能しない

于 2012-09-27T05:15:35.197 に答える