5
A
回答
2
爲了實現打開活動的功能,在收到通知後,應該在清單中給出該活動intent-filter
以偵聽一個動作。
在Notification和有效負載中,應該發送活動偵聽的動作。在Receiver中,可以觸發帶有這種操作的Intent
,這會打開活動,即使應用程序處於背景或關閉狀態。
4
Recive自定義消息在通知並根據KeyWork真或假的或指定的Word中,進入到活動 公共類MyFirebaseMessagingService擴展FirebaseMessagingService {
private static final String TAG = "FirebaseMessageService";
Bitmap bitmap;
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// There are two types of messages data messages and notification messages. Data messages are handled
// here in onMessageReceived whether the app is in the foreground or background. Data messages are the type
// traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app
// is in the foreground. When the app is in the background an automatically generated notification is displayed.
// When the user taps on the notification they are returned to the app. Messages containing both notification
// and data payloads are treated as notification messages. The Firebase console always sends notification
// messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options
//
Log.d(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
//The message which i send will have keys named [message, image, AnotherActivity] and corresponding values.
//You can change as per the requirement.
//message will contain the Push Message
String message = remoteMessage.getData().get("message");
//imageUri will contain URL of the image to be displayed with Notification
String imageUri = remoteMessage.getData().get("image");
//If the key AnotherActivity has value as True then when the user taps on notification, in the app AnotherActivity will be opened.
//If the key AnotherActivity has value as False then when the user taps on notification, in the app MainActivity will be opened.
String TrueOrFlase = remoteMessage.getData().get("AnotherActivity");
//To get a Bitmap image from the URL received
bitmap = getBitmapfromUrl(imageUri);
sendNotification(message, bitmap, TrueOrFlase);
}
/**
* Create and show a simple notification containing the received FCM message.
*/
private void sendNotification(String messageBody, Bitmap image, String TrueOrFalse) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("AnotherActivity", TrueOrFalse);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setLargeIcon(image)/*Notification icon image*/
.setSmallIcon(R.drawable.firebase_icon)
.setContentTitle(messageBody)
.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(image))/*Notification with Image*/
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
This is AnotherActivity
//如果通知消息被竊聽,任何數據伴隨着通知 //消息在意向演員中可用。在這個項目中,啓動器 //意圖在通知被點擊時觸發,所以任何伴隨的數據將在這裏處理 。如果您希望激發不同的意圖,請將通知消息的click_action //字段設置爲所需的意圖。啓動器意圖 //在沒有指定click_action時使用。 // //處理伴隨通知消息的可能數據。 如果(getIntent()。getExtras()!= NULL){
for (String key : getIntent().getExtras().keySet()) {
String value = getIntent().getExtras().getString(key);
if (key.equals("AnotherActivity") && value.equals("True")) {
Intent intent = new Intent(this, AnotherActivity.class);
intent.putExtra("value", value);
startActivity(intent);
finish();
}
}
}
這是數據
{ "data": {
"image": "https://ibin.co/2t1lLdpfS06F.png",
"message": "Firebase Push Message Using API"
"AnotherActivity": "True"
},
"to" : "f25gYF3***********************HLI"
}
相關問題
- 1. 如何在點擊通知後打開特定活動?
- 2. 將浮動操作按鈕轉換爲Android中的活動
- 3. 如何打開點擊操作欄中按鈕的新活動?
- 4. 如何重新打開通知中的活動點擊我android
- 5. 如何在通知操作中顯示特定的viewcontroler?
- 6. 根據通知操作點擊打開不同的活動
- 7. 如何使用通知中的操作而無需啓動活動
- 8. 在FCM中點擊通知時打開特定活動
- 9. 意圖特定活動時,推送通知中點擊。
- 10. 將按鈕添加到Android活動中的操作欄
- 11. 通知不取消操作點擊android
- 12. Android通知操作不可點擊
- 13. 點擊通知並未啓動特定活動
- 14. 如何通過點擊本地通知確定應用程序變爲活動
- 15. 特定按鈕點擊後的操作
- 16. 無法從使用Firebase的通知中啓動特定活動
- 17. Android Java:如何將活動中的值傳遞給通知欄
- 18. 如何將GCM通知消息轉換爲android中的活動?
- 19. Android:關閉通知的通知操作
- 20. Android - 用戶點擊酒吧中的通知時如何不啓動活動
- 21. 如何通知不活動的活動?
- 22. 隱藏或刪除特定活動|上的操作欄Android的
- 23. Firebase通知單擊操作活動父活動
- 24. 如何識別來自特定NSManagedObjectContext保存操作的通知?
- 25. 如何在Android應用中製作按鈕開關活動
- 26. 如何通過點擊特定的按鈕激活keydown事件?
- 27. 如果應用在推送通知中處於活動狀態
- 28. 如何隱藏特定活動的通知?
- 29. 如何打開推送通知的特定活動?
- 30. 如何在通知上添加點按操作?
什麼是你的使用情況? –
從api我得到不同的情況通知意圖與不同的活動。當應用程序打開工作正常,但在後臺應用程序它不工作 – Pradip
如果我正確理解問題,您將不得不添加意向過濾器到所有這些活動,需要在通知到達時打開。您可以在通知有效內容中包含活動網址,並在Receiver中使用它來啓動該操作的意圖。 –