비슷한 질문이 있지만 해결책이 없습니다. 브로드 캐스트 리시버가 SMS를 가로 채고 SMS 텍스트를 다른 활동으로 전달했습니다. 다른 활동에는 최근 수신 된 텍스트가 표시되어야합니다. 하지만 다른 활동은 앱을 처음 시작한 후에받은 첫 번째 텍스트를 항상 표시합니다. 새 문자 메시지가 표시되지 않습니다.방송 수신기에서 활동으로 보류중인 의도 - 이전 데이터 수신
내가 시도한 것 : 계류중인 의도 (고유 한 무작위 int 및 모든 4 개의 업데이트 옵션) 매개 변수로 재생 - 지금까지 도움이되었습니다.
PendingIntent contentIntent = PendingIntent.getActivity(context, **rand.nextInt(50) + 1**, intent, **FLAG_UPDATE_CURRENT**);
브로드 캐스트 수신기의 관련 코드는 다음과 같습니다. 알림도 트리거되어 매번 새롭고 올바른 텍스트가 표시됩니다.
private void showNotification(Context context) {
Intent intent = new Intent(context, DisplayMSG.class);
intent.putExtra(EXTRA_MESSAGE, str);
Random rand = new Random();
PendingIntent contentIntent = PendingIntent.getActivity(context, rand.nextInt(50) + 1, intent, FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("RPT Notification")
.setContentText(str + Integer.toString(n));
mBuilder.setContentIntent(contentIntent);
mBuilder.setDefaults(Notification.DEFAULT_SOUND);
mBuilder.setAutoCancel(true);
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
}
그리고 여기가 수신 활동의 부분 :
Intent intent = getIntent();
String message = intent.getStringExtra(SmsReceiver.EXTRA_MESSAGE);
TextView textView = (TextView) findViewById(R.id.tView);
textView.setText(message);
당신이 더 많은 코드가 필요하면 알려주세요. 그러나 기본적으로 효과가 있기 때문에 이것이 충분해야한다고 생각합니다. 새로운 텍스트를 전송하지 않고 있습니다.
편집 : 여기 CommonsWare하는 덕분에이 솔루션은, 그냥 수신 활동에이 방법을 추가됩니다
@Override
protected void onNewIntent(Intent intent)
{
super.onNewIntent(intent);
TextView textView = (TextView) findViewById(R.id.tView);
textView.setText(intent.getStringExtra(SmsReceiver.EXTRA_MESSAGE));
}
감사합니다. 5 분 안에 문제가 해결되었습니다. :) – user3503212