Ahmed Ezzat
Ahmed Ezzat

Reputation: 85

send Firebase notification from another app

Is there any possible way to invoke onMessageReceived from FirebaseMessagingService with code in MainActivity.java from another package (apk) without using Firebase APIs or connecting to FCM Server?

MyFirebaseMessagingService.java

public final class MyFirebaseMessagingService extends FirebaseMessagingService {
    public void onMessageReceived(RemoteMessage remoteMessage) {
         // I'm interested in this method
    }

    public void onNewToken(String str) {
        // code
    }
}

Upvotes: 0

Views: 425

Answers (2)

Doug Stevenson
Doug Stevenson

Reputation: 317467

You will want to read the documentation for FirebaseInstanceIdReceiver. This is the BroadcastReceiver that receives push messages from FCM. It's merged in the manifest like this:

 <receiver
     android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
     android:exported="true"
     android:permission="com.google.android.c2dm.permission.SEND" >
     <intent-filter>
         <action android:name="com.google.android.c2dm.intent.RECEIVE" />
         <category android:name="YOUR_PACKAGE_NAME" />
     </intent-filter>
 </receiver>

As stated in that documentation:

The com.google.android.c2dm.permission.SEND permission is held by Google Play services. This prevents other apps from invoking the broadcast receiver.

So, unless your code is running in the Google Play services app process, or some other similar process installed via root access that has the required permission, it's not going to be possible to forcibly deliver a message.

Upvotes: 2

shafayat hossain
shafayat hossain

Reputation: 1129

Try calling REST API from your MainActivity.java of another package. API documentation can be found here. Provide proper server key to send FCM to your another package's app.

Upvotes: 0

Related Questions