我正在通过我自己的Web服务发送Firebase通知,如下所示.
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $tokens,
'data' => $message
);
$headers = array(
'Authorization:key = SERVER_KEY ',
'Content-Type: application/json'
);
Run Code Online (Sandbox Code Playgroud)
1.当App在前台和后台没有任何问题时,通知即将到来,但如果我从最近的托盘中删除应用程序然后通知没有到来,我必须处理这个任何解决方案吗?(就像Whatsup通知显示所有场景甚至我强制停止此应用程序的设置)
2.一旦我收到通知,从"onMessageReceived"如何将这些消息,正文内容传递给我的Activity/Fragments?
3.在某些情况下,我想向所有人发送通知,而不是将所有令牌添加到数组中.任何其他方式处理像"发送给所有"这样的东西?
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MsgService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Data Payload : " + remoteMessage.getData());
sendNotification(remoteMessage.getData().get("message"));
}
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri …Run Code Online (Sandbox Code Playgroud) notifications android android-notifications firebase firebase-cloud-messaging
我已经在我的示例 android 应用程序中配置了 firebase 动态链接,
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="example.com"
android:scheme="https"/>
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
它工作正常当我单击动态链接时,唯一的问题是它在同一个链接共享应用程序(如 WhatsUp、Messages)中打开。
在 Whatsup 或 Messages 应用程序中单击动态链接时如何单独打开我的应用程序。
请参考以下截图
android deep-linking firebase deeplink firebase-dynamic-links