0

My App have a code segment that get installed applications in phone. and I use the getInstalledPackages API. and I found this will make my application crash and I will get java.lang.RuntimeException: Package manager has died.

My question is why it it happened and how to solve it(to get installed applications) by this way or other way?

this is one of the reports:

at android.app.ApplicationPackageManager.getApplicationInfo(ApplicationPackageManager.java:224)
at com.baidu.location.ae.a(Unknown Source)
at com.baidu.location.LocationClient.getAccessKey(Unknown Source)
at com.baidu.location.LocationClient.cy(Unknown Source)
at com.baidu.location.LocationClient.do(Unknown Source)
at com.baidu.location.LocationClient$a.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5050)
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:805)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:621)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.os.DeadObjectException
at android.os.BinderProxy.transact(Native Method)
at android.content.pm.IPackageManager$Stub$Proxy.getApplicationInfo(IPackageManager.java:1740)
at android.app.ApplicationPackageManager.getApplicationInfo(ApplicationPackageManager.java:219)
Alex Wang
  • 131
  • 1
  • 1
  • 10
  • Sharing code snippet will help us to understand what you did wrong – Hitesh Sahu Jul 01 '16 at 03:10
  • Possible duplicate of [Android Package manager has died with TransactionTooLargeException](http://stackoverflow.com/questions/24253976/android-package-manager-has-died-with-transactiontoolargeexception) – Hitesh Sahu Jul 01 '16 at 03:18

1 Answers1

0

Following is the code to get the list of activities/applications installed on Android :

final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent, 0);

You will get all the necessary data in the ResolveInfo to start a application. You can check ResolveInfo javadoc here.

Sathish Kumar J
  • 4,280
  • 1
  • 20
  • 48
  • Thanks for your comment, but this method clearly will not work at the same condition.We all are using PackageManager while package manger has die.. – Alex Wang Jul 01 '16 at 06:00