FirebaseMessaging: не найдено действий для запуска приложения - PullRequest
0 голосов
/ 17 мая 2019

Я пытаюсь правильно получить сообщение от FireBase, когда мое приложение работает в фоновом режиме, но не работает с anithing.Я видел некоторые проблемы со Stackoverflow, подобные моей, но ничего не работало.Может ли кто-нибудь помочь мне найти проблему?

Мне нужно сделать это, когда мое приложение работает в фоновом режиме, но не работает.

здесь AndoridManifest.xml

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />

<uses-feature android:name="android.hardware.type.watch" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@android:style/Theme.DeviceDefault"
    tools:targetApi="ice_cream_sandwich">


    <service
        android:name=".MyfirebaseMessagingService" android:exported="false" >
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"/>
        </intent-filter>
    </service>

    <service
        android:name=".MyFirebaseInstanceIDService" android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
    </service>

    <uses-library
        android:name="com.google.android.wearable"
        android:required="true" />
    <!--
           Set to true if your app is Standalone, that is, it does not require the handheld
           app to run.
    -->
    <meta-data
        android:name="com.google.android.wearable.standalone"
        android:value="true" />

    <!-- [START fcm_default_channel] -->
    <!-- [START fcm_default_channel] -->
    <meta-data
        android:name="com.google.firebase.messaging.default_notification_channel_id"
        android:value="@string/default_notification_channel_id" />


    <activity
        android:name=".MainActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />

            <!--<action android:name="android.intent.action.VIEW" />-->

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="gizmos"
                android:scheme="example" />
        </intent-filter>
    </activity>



</application>

MyfirebaseMessagingService.java:

   public class MyfirebaseMessagingService extends        FirebaseMessagingService {
       public static String TAG = "MyFirebaseMsgService";

       private LocalBroadcastManager broadcaster;



@Override
public void onCreate() {
    super.onCreate();
    createNotificationChannel();

    broadcaster = LocalBroadcastManager.getInstance(this);
}

@Override
public void onDestroy() {
    super.onDestroy();
}
private void createNotificationChannel() {
    // Create the NotificationChannel, but only on API 26+ because
    // the NotificationChannel class is new and not in the support library
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        String channelId = getString(R.string.default_notification_channel_id);

        CharSequence name = getString(R.string.default_notification_channel_id);
        String description = getString(R.string.channel_description);
        int importance = NotificationManager.IMPORTANCE_DEFAULT;
        NotificationChannel channel = new NotificationChannel(channelId, name, importance);
        channel.setDescription(description);
        // Register the channel with the system; you can't change the importance
        // or other notification behaviors after this
        NotificationManager notificationManager = getSystemService(NotificationManager.class);
        notificationManager.createNotificationChannel(channel);
    }
}


@Override
public void onMessageReceived(RemoteMessage remoteMessage) {


    Log.d(TAG, "From: " + remoteMessage.getFrom());
    Intent home = new Intent(getApplicationContext(), MainActivity.class);
    home.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(home);

    // 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());

        Intent intent = new Intent("Data");
        intent.putExtra("messageFromCloud", remoteMessage.getNotification().getBody());
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        broadcaster.sendBroadcast(intent);
        if (intent.getExtras() != null)
        {
            RemoteMessage.Builder builder = new RemoteMessage.Builder("MyFirebaseMessagingService");

            for (String key : intent.getExtras().keySet())
            {
                builder.addData(key, intent.getExtras().get(key).toString());
            }

            onMessageReceived(builder.build());
        }
    }


}
   }

1 Ответ

1 голос
/ 17 мая 2019

Если вы хотите использовать MainActivity в качестве Activity из Notification click активности, тогда вам нужно кодировать как:

<activity
    android:name=".MainActivity"
    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />

        <category android:name="android.intent.category.BROWSABLE" />

        <data
            android:host="gizmos"
            android:scheme="example" />
    </intent-filter>
</activity>

Он будет автоматически перенаправлен на MainAcitivity на Notification click.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...