알림 클릭 이벤트에 대한 세부 활동을 열려고합니다. 여기에 PendingIntent
및 Notification
클래스가 있습니다. 추가 된 addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
도 추가되었습니다. PendingIntent.FLAG_UPDATE_CURRENT
. 나는 사이트에서 모든 주제를 검색해이 솔루션을 찾았습니다. 모두 시도해 보았습니다. 여기 FCM 알림이 작동하지 않는 PendingIntent
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO(developer): Handle FCM messages here.
// If the application is in the foreground handle both data and notification messages here.
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated. See sendNotification method below.
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
ArrayList<String> notificationData = new ArrayList<String >(remoteMessage.getData().values());
String fortuneID = notificationData.get(0);
sendNotification(remoteMessage.getNotification().getBody(),fortuneID);
}
// [END receive_message]
/**
* Create and show a simple notification containing the received FCM message.
*
* @param messageBody FCM message body received.
*/
private void sendNotification(String messageBody,String notificationID) {
Intent configureIntent = new Intent(getApplicationContext(), FalDetayActivity.class);
configureIntent.putExtra("extra", "123123");
configureIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
configureIntent.setAction("dummy_unique_action_identifyer" + "123123");
int dummyuniqueInt = new Random().nextInt(543254);
PendingIntent pendingClearScreenIntent = PendingIntent.getBroadcast(getApplicationContext(), dummyuniqueInt, configureIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("myApp")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingClearScreenIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1 /* ID of notification */, notificationBuilder.build());
}
}
는
getBundle
부분
MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String quote = getIntent().getStringExtra("extra");
...
}
또 다른 내가 FalDetailActivity
을 열려는 문제가 있지만 항상 항상 열려 MainActiviy
및 getIntent()
null을 반환합니다. 아마, PendingIntent
이 설정되지 않았습니다.이 코드를 확인하시기 바랍니다. 감사합니다 ... 뭔가
Intent configureIntent = new Intent(getApplicationContext(), FalDetayActivity.class);
configureIntent.putExtra("extra", "123123");
configureIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingClearScreenIntent = PendingIntent.getActivity(getApplicationContext(), 0, configureIntent, PendingIntent.FLAG_UPDATE_CURRENT);
** configureIntent.setAction ("dummy_unique_action_identifyer"+ "123123"); ** 이 줄과 try를 제거하십시오. –
나는 아직도 대신 ** PendingIntent.getBroadcast() **이 사용 ** PendingIntent.getActivity() ** –
작동하지 제거 펼친 상태 항목이 클릭됩니다. 이것이 활동 인 경우 ** FLAG_ACTIVITY_NEW_TASK ** 플래그를 포함해야합니다. 이 플래그를 추가하십시오. –