0

通知の意図を介していくつかのデータ (文字列) を送信しています。ただし、通知によって起動されたアクティビティで受信しようとすると、何も受信しません。これが私のコードです。助けてください。

これは、通知のコードです。

int icon=R.drawable.ic_launcher;
                String ticket="Encrypted message";
                long when=System.currentTimeMillis();
                NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                Context context1 =getApplicationContext();
                String expandedText="You've received an encrypted message, click to view";
                String expandedTitle="Encrypted Message";
                Notification notification = new Notification(icon, ticket, when);
                Intent intent1=new Intent(context,Try.class);
                intent1.putExtra("MSG","Jumbo");
                PendingIntent launchIntent=PendingIntent.getActivity(context,0, intent1,0);

notification.setLatestEventInfo(context,expandedTitle,expandedText,launchIntent);
                mNotificationManager.notify(1,notification);

そして、ここに私が Try.class でそれを受け取る方法があります:

t = (TextView)findViewById(R.id.dec);
        String d = "";
        Intent I = getIntent();
        d = I.getStringExtra("MSG");
        String text = "This is an example";
        t.setText(d);

エラーはありません-実行するとTextViewは何も設定されません

4

4 に答える 4

0

通知機能で setResult (Activity.RESULT_OK, Intent) を呼び出したことはありますか? そうしないと、Android は「呼び出し」アクティビティを再開しません。

于 2012-11-28T17:10:52.963 に答える
0

それはうまくいくはずです、「d」の値をログに記録してみてください

Log.d("Value of D", d);

あなたの問題は、TextViewt が適切に設定されていないため、結果が表示されないことだと思います。

于 2012-11-28T17:17:09.490 に答える
0

それ以外の

Intent intent1=new Intent(context,Try.class);

への変更

Intent intent1=new Intent(YourActivity.this,Try.class);

onCreate()メソッドで試してみる

t = (TextView)findViewById(R.id.dec);

Bundle extras = getIntent().getExtras(); 
String d;

 if (extras != null) {
      d = extras.getString("MSG");
  }   
t.setText(d);
于 2012-11-28T17:07:25.160 に答える
0

getIntent() はそこでは機能しません。アクティビティで onNewIntent メソッドをオーバーライドしてみてください。

于 2012-11-28T16:59:43.283 に答える