javaandroidbroadcastreceiverandroid-securityexception

java.lang.SecurityException:Unable to find app for caller android.app.ApplicationThreadProxy when registering receiver android.content.IIntentReceiver


This error occurs when users have the first login after installing my app. But in the next launch (when the user already logged in) the app works fine.

In my app I am using a BroadcastReceiver which is used for checking internet connectivity.

So to be specific, the app is having above mentioned Exception while registering that BroadcastReceiver. Any help would be highly appereciated!

My logcat is like below

java.lang.RuntimeException: Unable to resume activity {com.android.myproject/com.android.myproject.MapActivity}: java.lang.SecurityException: Unable to find app for caller android.app.ApplicationThreadProxy@43155660 (pid=24211) when registering receiver android.content.IIntentReceiver$Stub$Proxy@43151368
1 at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2762)
2 at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2791)
3 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1288)
4 at android.os.Handler.dispatchMessage(Handler.java:99)
5 at android.os.Looper.loop(Looper.java:137)
6 at android.app.ActivityThread.main(ActivityThread.java:5095)
7 at java.lang.reflect.Method.invokeNative(Native Method)
8 at java.lang.reflect.Method.invoke(Method.java:511)
9 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:845)
10 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
11 at dalvik.system.NativeStart.main(Native Method)
12Caused by: java.lang.SecurityException: Unable to find app for caller android.app.ApplicationThreadProxy@43155660 (pid=24211) when registering receiver android.content.IIntentReceiver$Stub$Proxy@43151368
13 at android.os.Parcel.readException(Parcel.java:1425)
14 at android.os.Parcel.readException(Parcel.java:1379)
15 at android.app.ActivityManagerProxy.registerReceiver(ActivityManagerNative.java:2228)
16 at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1356)
17 at android.app.ContextImpl.registerReceiver(ContextImpl.java:1324)
18 at android.app.ContextImpl.registerReceiver(ContextImpl.java:1318)
19 at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:423)
20 at com.android.myproject.MapActivity.onResumeOperations(MapActivity.java:584)
21 at com.android.myproject.MapActivity.onResume(MapActivity.java:618)
22 at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1185)
23 at android.app.Activity.performResume(Activity.java:5203)
24 at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2752)

In order to clarify my question, my onResumeOperations() look like

 public void onResumeOperations(){
    if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER )&& !isFinishing()) {
        ShowGpsDialog();
    } else {
        removeGpsDialog();
    }

    registerReceiver(internetConnectionReciever, new IntentFilter(
            "android.net.conn.CONNECTIVITY_CHANGE"));
    registerReceiver(GpsChangeReceiver, new IntentFilter(
            LocationManager.PROVIDERS_CHANGED_ACTION));
    isRecieverRegistered = true;

    if (AndyUtils.isNetworkAvailable(this)
            && manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        if (!isDataRecieved) {

            checkStatus();
            startLocationUpdateService();
           // getPreReservations();
        }
    }

    registerIsApproved();

    startRepeatingChecker();
}

this onResumeOperations() is called in onResume(). And as I previously mentioned, the problem occurs when registering internetConnectionReceiver.


Solution

  • This error means there was an error communicating with another process handling an Intent.

    this error can happen sending an intent with intent extras being too big, bigger than max transaction size (1Mb).

    Passing High resolution photos or big file via extras is not recommended, the best practice is to save the file on the external storage get a Uri reference to it and send this ref as String in your intent's extra

    yourIntent.putExtra("key", yourUri.toString)
    

    Also try android:exported="true" in activity tag

    <activity
    android:name=".your_activity"
    android:label="@string/app_name"
    android:exported="true">
    

    setting the exported tag to true means that another application not related to my app can access it