Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android.os.TransactionTooLargeException retrieving installed applications

Tags:

java

android

xml

I'm recovering all the applications installed on the device and I stumbled upon this error.

java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:811)
Caused by: java.lang.RuntimeException: Package manager has died
at android.app.ApplicationPackageManager.queryIntentActivitiesAsUser(ApplicationPackageManager.java:499)
at android.app.ApplicationPackageManager.queryIntentActivities(ApplicationPackageManager.java:485)
at com.name.package.MyClass$RetrieveApps.doInBackground(MyClass.java:363)
at com.name.package.MyClass$RetrieveApps.doInBackground(MyClass.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
... 4 more
Caused by: android.os.TransactionTooLargeException
at android.os.BinderProxy.transact(Native Method)
at android.content.pm.IPackageManager$Stub$Proxy.queryIntentActivities(IPackageManager.java:2165)
at android.app.ApplicationPackageManager.queryIntentActivitiesAsUser(ApplicationPackageManager.java:493)
... 9 more

In doInBackground() method i use this code to retrieve the installed apps.

    PackageManager packageManager = getPackageManager();
    List<ResolveInfo> mResolveInfo;
    Intent queryIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
    mResolveInfo = packageManager.queryIntentActivities(queryIntent, 0);
    for (ResolveInfo ri : resolveInfos) {
        Class class = new Class();
        class.icon = ri.loadIcon(packageManager);
        class.label = ri.loadLabel(packageManager);
        class.packagename = ri.activityInfo.packageName;
        class.packageclass = ri.activityInfo.name;
        class.componentName = new ComponentName(class.packagename, class.packageclass);
        Intent i = new Intent(Intent.ACTION_MAIN);
        i.addCategory(Intent.CATEGORY_LAUNCHER);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        i.setComponent(ai.componentName);
        class.intent = i;
        myArrayList.add(class);

The line where the crash occurs is this:

mResolveInfo = packageManager.queryIntentActivities(queryIntent, 0);

Reading on stack overflow I understand that this may be caused by the fact that you have many applications installed. The question now is, how can you solve? Is there any solution? If yes, which one? Thanks.

like image 243
user3289078 Avatar asked Feb 09 '14 07:02

user3289078


1 Answers

I'm looking for the same solution. Is there any way to do a partial list of installed applications?

I have the same problem in my app.

List<PackageInfo> packs = pm.getInstalledPackages(0);

If the user has a large number of apps I get this in logcat:

Caused by: java.lang.RuntimeException: Package manager has died at android.app.ApplicationPackageManager.getInstalledPackages(ApplicationPackageManager.java:424)

Caused by: android.os.TransactionTooLargeException at android.os.BinderProxy.transact(Native Method) at android.content.pm.IPackageManager$Stub$Proxy.getInstalledPackages(IPackageManager.java:2363)

Update!

I was able to figure out a way. See this answer that I gave in another post:

Package manager has died

like image 182
Will R. Avatar answered Nov 06 '22 02:11

Will R.