Android getLaunchIntentForPackage returns null - android

I am making the following call:
Intent launchIntent = context.getPackageManager()
.getLaunchIntentForPackage(packageName);
It crashes with NPE with the following stackTrace:
java.lang.NullPointerException at
android.app.Instrumentation.execStartActivity(Instrumentation.java:1423)
at android.app.Activity.startActivityForResult(Activity.java:3584) at
android.app.Activity.startActivityForResult(Activity.java:3545) at
android.support.v4.app.FragmentActivity.void
startActivityForResult(android.content.Intent,int)(SourceFile:817) at
android.app.Activity.startActivity(Activity.java:3787) at
android.app.Activity.startActivity(Activity.java:3755) at
utils.AppsLauncher.voidlaunchApp(android.content.Context,java.lang.String)(SourceFile:100)
at utils.AppsLauncher.void
launchAppIfInstalledOtherwiseMarket(android.app.Activity,java.lang.String,utils.AppReportingParams)(SourceFile:73)
at utils.AppsLauncher.void
launchAppIfInstalledOtherwiseMarket(android.app.Activity,java.lang.String)(SourceFile:51)
at adapters.BaseGamesListAdapter.void
launchAppIfInstalledOtherwiseMarket(java.lang.String)(SourceFile:119)
at
adapters.UserGamesAdapter$UserGameUIHolder$1.void
onClick(android.view.View)(SourceFile:198) at
android.view.View.performClick(View.java:4658) at
android.view.View$PerformClick.run(View.java:19461) at
android.os.Handler.handleCallback(Handler.java:733) at
android.os.Handler.dispatchMessage(Handler.java:95) at
android.os.Looper.loop(Looper.java:146) at
android.app.ActivityThread.main(ActivityThread.java:5692) at
java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:515) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107) at
dalvik.system.NativeStart.main(Native Method)
I assume that getLaunchIntentForPackage(packageName) returns a null Intent. I can't figure out in GREPcode why exactly it returns null: (http://grepcode.com/file/repo1.maven.org/maven2/org.robolectric/android-all/5.0.0_r2-robolectric-0/android/app/ApplicationPackageManager.java#ApplicationPackageManager.getLaunchIntentForPackage%28java.lang.String%29)
It is important to note that the package does indeed exist and is installed on the device.

The context or context.getPackageManager() is null.

Related

getActiveNotifications() make out of memory

I have a problem with fatal exeption. I need to get notifications from phone. That line make it:
StatusBarNotification[] notificationsArray = getActiveNotifications();
But it make error sometimes on some devices:
Fatal Exception: java.lang.OutOfMemoryError
at android.graphics.Bitmap.nativeCreateFromParcel(Bitmap.java)
at android.graphics.Bitmap.access$000(Bitmap.java:34)
at android.graphics.Bitmap$1.createFromParcel(Bitmap.java:1565)
at android.graphics.Bitmap$1.createFromParcel(Bitmap.java:1557)
at android.widget.RemoteViews$BitmapCache.(RemoteViews.java)
at android.widget.RemoteViews.(RemoteViews.java)
at android.widget.RemoteViews.(RemoteViews.java)
at android.widget.RemoteViews$2.createFromParcel(RemoteViews.java:3049)
at android.widget.RemoteViews$2.createFromParcel(RemoteViews.java:3047)
at android.app.Notification.(Notification.java)
at android.service.notification.StatusBarNotification.(StatusBarNotification.java)
at android.service.notification.StatusBarNotification$1.createFromParcel(StatusBarNotification.java:121)
at android.service.notification.StatusBarNotification$1.createFromParcel(StatusBarNotification.java:118)
at android.os.Parcel.createTypedArray(Parcel.java:1935)
at android.app.INotificationManager$Stub$Proxy.getActiveNotificationsFromListener(INotificationManager.java:528)
at android.service.notification.NotificationListenerService.getActiveNotifications(NotificationListenerService.java:149)
at com.hexati.lockscreentemplate.service.NotificationService.sendAll(NotificationService.java:380)
at com.hexati.lockscreentemplate.service.NotificationService.access$200(NotificationService.java:60)
at com.hexati.lockscreentemplate.service.NotificationService$NotificationsReceiver.onReceive(NotificationService.java:419)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:772)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5487)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(NativeStart.java)
How I can fix that problem?

Can I know how Activity was started by looking at crash stack trace?

I have a NPE and it seems that my Activity is started in some weird way/context as some components (constructed by dependency injection - dagger 2 - which are normally instantiated and working well) are null. All I have is call stack trace with NPE on top of it.
So can I say that my Activity was created/recreated in some special way by examining this:
//... and then all onCreate goes on and finally a NPE on top of it
at android.app.Activity.performCreate(Activity.java:5447)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.access$800(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5590)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(NativeStart.java)

java.lang.NullPointerException at GoogleApiActivity

I'm using Crashlytics for my android app, and I have many crashes at ActivityThread.java: android.app.ActivityThread.deliverResults
I put some stack traces here:
Fatal Exception: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=0, data=null} to activity {me.robano.android/com.google.android.gms.common.api.GoogleApiActivity}: java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:3641)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3684)
at android.app.ActivityThread.access$1300(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5584)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.lang.NullPointerException
at com.google.android.gms.common.api.GoogleApiActivity.zza(Unknown Source)
at com.google.android.gms.common.api.GoogleApiActivity.onActivityResult(Unknown Source)
at android.app.Activity.dispatchActivityResult(Activity.java:5634)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3637)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3684)
at android.app.ActivityThread.access$1300(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5584)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(NativeStart.java)
I'm also using google firebase in my app.
please help!
thanks
Upgrading the SDK to the latest version 9.4 of the Google Play Service should fix this issue.
The problem is definitely in the new Google Services (9.0.0 to 9.4.0). It tries to start something that returns null to the onActivityResult.
Probably the only way to fix this:
PackageManager pm = getPackageManager();
pm.setComponentEnabledSetting(new ComponentName(this, GoogleApiActivity.class), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
This is a bug in the Google Play Services SDK, up to 9.4.0. The fix should be in the next release, sorry about that.

Package Manager has died, DeadObjectException

We use our app on only one device type and we get this error pretty often on it.
The only instance for PackageManager is a BootupReceiver:
public class RestartHelper extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent) {
Logger.getInstance().Log("Restart received");
Intent i = context.getPackageManager().getLaunchIntentForPackage( context.getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(i);
}
}
Exception:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.MainActivity}: java.lang.RuntimeException: Package manager has died
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Package manager has died
at android.app.ApplicationPackageManager.getActivityInfo(ApplicationPackageManager.java:239)
at android.support.v4.app.NavUtils.getParentActivityName(NavUtils.java:301)
at android.support.v4.app.NavUtils.getParentActivityName(NavUtils.java:281)
at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:152)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:60)
at com.cotris.roosapp.StandardActivity.onCreate(StandardActivity.java:49)
at com.cotris.roosapp.MainActivity.onCreate(MainActivity.java:64)
at android.app.Activity.performCreate(Activity.java:5264)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
... 11 more
Caused by: android.os.DeadObjectException
at android.os.BinderProxy.transact(Native Method)
at android.content.pm.IPackageManager$Stub$Proxy.getActivityInfo(IPackageManager.java:1791)
at android.app.ApplicationPackageManager.getActivityInfo(ApplicationPackageManager.java:234)
... 20 more
Is this error hardware/system related?
Obviously there has another PackageManger call but not only in RestartHelper.java:
at com.cotris.roosapp.StandardActivity.onCreate(StandardActivity.java:49)
You man need to check the code detail in that.
The android.os.DeadObjectException means that you link to something, that does not exist any more.
the solution for my case was a hardware related problem, which created all kind of crashes of system processes in the background on the device.

DevicePolicyManger().getCurrentFailedPasswordAttempts crashes app

Seems like some of the DeviceAdmin functionality has been broken in Lollipop, at least on my Nexus 5.
This works perfectly on KitKat, JellyBean and Ice Cream Sandwich
#Override
public void onPasswordFailed(Context context, Intent intent) {
DevicePolicyManager policyManager = (DevicePolicyManager)context.getSystemService(Context.DEVICE_POLICY_SERVICE);
if(policyManager != null){
int attempts = policyManager.getCurrentFailedPasswordAttempts();
Log.v("TAG", "Attempts = " + attempts);
}
}
But on my Nexus 5 with Android 5.0 Lollipop it produces the following error:
11-24 16:11:50.117 27053-27053/com.example.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.myapp, PID: 27053
java.lang.RuntimeException: Unable to start receiver com.example.myapp.receivers.AdminReceiver: java.lang.NullPointerException: Attempt to read from field 'int android.content.pm.UserInfo.id' on a null object reference
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2586)
at android.app.ActivityThread.access$1700(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NullPointerException: Attempt to read from field 'int android.content.pm.UserInfo.id' on a null object reference
at android.os.Parcel.readException(Parcel.java:1546)
at android.os.Parcel.readException(Parcel.java:1493)
at android.app.admin.IDevicePolicyManager$Stub$Proxy.getCurrentFailedPasswordAttempts(IDevicePolicyManager.java:2476)
at android.app.admin.DevicePolicyManager.getCurrentFailedPasswordAttempts(DevicePolicyManager.java:1261)
at com.example.myapp.receivers.AdminReceiver.onPasswordFailed(AdminReceiver.java:48)
at android.app.admin.DeviceAdminReceiver.onReceive(DeviceAdminReceiver.java:417)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2579)
            at android.app.ActivityThread.access$1700(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
It's been reported as an issue in the L-preview as well.
My question, what is causing this?
I have got same error then I realised that it may not work for the version 5.0 and above versions.So what I did is I am checking number of wrong attempts programmatically.Like If the someone wants to unlock pattern or pin if he enters wrong then receiver will catch and calls the passwordFailed() method.So I created on SharedPreference object and I am storing the number of passwordFailed() method is called. Based on that I am getting number of wrong patterns.I think this is correct way or not I don't know.

Categories

Resources