ForzaJuve
ForzaJuve

Reputation: 75

Installing .apk with IntentFilters on Android 12

I want to install the .apk of my Android Application on an Android 12 device. The application contains two IntentFilters which I read might lead to some problems when installing on Android 12. The installations works perfectly fine on Android 10 as well as Android 11.

MainActivity.cs

[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true, Exported = true)]

AndroidMaifest.xml

<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="true" />


<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" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="${applicationId}" />
        </intent-filter>
    </receiver>

Is there anything I missed that needs to be changed in order to work on Android 12?

Edit:

I changed some parts of the AndroidManifest.xml now, but I still can't get it working. I am a little bit clueless which settings I need to change in order to avoid the error: ADB0010: Mono.AndroidTools.InstallFailedException: Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present]

FirebaseMessagingService.cs:

[Service]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]

public override void OnNewToken(string p0)
    {
        Log.Debug(TAG, "Refreshed token: " + p0);
        Task task = SendRegistrationToServer(p0);
        task.Wait();
        token = FirebaseInstanceId.Instance.Token;
    }

AndroidManifest.xml:

<service android:name="MyFirebaseMessagingService" android:exported="false">
    <intent-filter>
                <action android:name="com.google.android.c2dm.intent.MESSAGING_EVENT" />
      <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
              <category android:name="${applicationId}" />
        </intent-filter>
    </service>

Edit 2: I can install the app on Android 12 now. Unfortunately another problem occured, when I open the app for the first time the FCM token should be generated and fire the "OnNewToken"-Method. This method is not fired when I use Android 12 but it works on Android 11 and Android 10.

MainActivity.cs

[Service(Exported = false)]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT", "com.google.firebase.REGISTRATION" })]
public override void OnNewToken(string p0)
    {
        Log.Debug(TAG, "Refreshed token: " + p0);
        Task task = SendRegistrationToServer(p0);
        task.Wait();
        token = FirebaseInstanceId.Instance.Token;
    }

Upvotes: 0

Views: 384

Answers (1)

Liyun Zhang - MSFT
Liyun Zhang - MSFT

Reputation: 14509

Had you tried to uninstall the app from the device and install it again? It seems that the OnNewToken method will just call once when the app run on the device at first time.

In addition, you can try to add the following code into the intent filter:

"com.google.firebase.INSTANCE_ID_EVENT" 

Upvotes: 0

Related Questions