Reputation: 13
Updated my react native app target sdk version to 34 but got error One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED so added this code in MainApplication class
registered receiver in mainapplication.java class
@Override
public Intent registerReceiver(@Nullable BroadcastReceiver receiver, IntentFilter filter) {
if (Build.VERSION.SDK_INT >= 34 && getApplicationInfo().targetSdkVersion >= 34) {
return super.registerReceiver(receiver, filter, Context.RECEIVER_EXPORTED);
} else {
return super.registerReceiver(receiver, filter);
}
}
but still getting error Service.startForeground() not allowed due to mAllowStartForeground false when triggered from Activity.onStop please help.
Upvotes: 0
Views: 97
Reputation: 102
I encountered the same issue, but this solution worked for me. Open MainApplication.java file and add this code
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import org.jetbrains.annotations.Nullable;
@Override
public Intent registerReceiver(@Nullable BroadcastReceiver receiver,
IntentFilter filter) {
if (Build.VERSION.SDK_INT >= 34 && getApplicationInfo().targetSdkVersion >=
34) {
return super.registerReceiver(receiver, filter,
Context.RECEIVER_EXPORTED);
} else {
return super.registerReceiver(receiver, filter);
}
}
make sure to add this code above the oncreate() method.
add this line inside android/app/build.gradle dependencies.
implementation 'org.jetbrains:annotations:16.0.2'
Upvotes: 0