简体   繁体   English

执行queryIntentActivities时android.os.TransactionTooLargeException

[英]android.os.TransactionTooLargeException when executing queryIntentActivities

I am using a device with Android 5.0.1 and when execute the function: 我在Android 5.0.1上使用设备,并且在执行该功能时:

Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
List<ResolveInfo> apps = manager.queryIntentActivities(mainIntent,0);

An exception of type TransactionTooLargeException is thrown .... I cannot use the flag: MATCH_DEFAULT_ONLY because I can't be limited to only those activities that support the CATEGORY_DEFAULT. 引发了TransactionTooLargeException类型的异常....我不能使用标志:MATCH_DEFAULT_ONLY,因为我不仅限于支持CATEGORY_DEFAULT的那些活动。 Looks that the problem is related with the amount of data returned, like many related issues that I found here at stackoverflow ... Is there a way to break this response? 看起来问题与返回的数据量有关,就像我在stackoverflow上发现的许多相关问题一样……有没有办法打破这种反应? Or is there a query, equivalent, or a combination of flags that allow get the same results making more than one query? 还是存在一个查询,等效查询或标志的组合,这些查询允许通过多个查询获得相同的结果? I am asking because is not clear to me the meaning of flag = 0 in documentation: https://developer.android.com/reference/android/content/pm/PackageManager.html#queryIntentActivities(android.content.Intent , int) 我问是因为我不清楚文档中flag = 0的含义: https : //developer.android.com/reference/android/content/pm/PackageManager.html#queryIntentActivities(android.content.Intent ,int)

May be I can query more than once, with different queries, and combine the results? 可能我可以使用不同的查询多次查询并合并结果吗?

You could chunk your query by being a bit more specific with how you form your Intent , and do multiple queries rather than 1 lump sum query. 您可以通过更加具体地构造Intent来对查询进行分块,并执行多个查询,而不是一次总付查询。 Right now, you're querying basically every application (potentially multiple for each) on the device (since everything that can launch will have a android.app.action.Main action), which goes over your allocation of the ~1 MB shared buffer parcel limit causing the exception: 现在,您正在查询设备上的每个应用程序(可能每个应用程序可能多个)(因为所有可以启动的应用程序都会有一个android.app.action.Main操作),该操作遍历了〜1 MB共享缓冲区的分配包裹限制导致异常:

From the docs: 从文档:

{ action=android.app.action.MAIN } matches all of the activities that can be used as top-level entry points into an application.

{ action=android.app.action.MAIN, category=android.app.category.LAUNCHER } is the actual intent used by the Launcher to populate its top-level list.

So, adding a category narrows the search results. 因此,添加类别会缩小搜索结果的范围。 If you need everything of action type "android.app.action.Main", use that as the action, then iterate over an additional set of categories ex sudo code: 如果您需要动作类型为“ android.app.action.Main”的所有内容,请将其用作动作,然后使用sudo代码遍历另一组类别

List<ResolveInfo> activities = new ArrayList<ResolveInfo>()

String[] categories = new String[] { android.app.category.LAUNCHER, additional... }

for(String category: categories){
   Intent mainIntent = new Intent(Intent.ACTION_MAIN)
   mainIntent.addCategory(category)
   List<ResolveInfo> matches = manager.queryIntentActivities(mainIntent, 0);  //You might want to use a better @ResolveInfoFlag to narrow your ResolveInfo data
   if(!matches.isEmpty()){
      activities.addAll(matches)
   }
}

You should also probably do a try catch, because when doing a MATCH_ALL, there's still no guarantee that the query won't be too large. 您可能还应该尝试捕获,因为在执行MATCH_ALL时,仍然不能保证查询不会太大。 There might be appropriate flags to help with this, but I'm not familiar with your use case. 可能有适当的标志可以帮助您解决此问题,但是我对您的用例不熟悉。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android.os.TransactionTooLargeException检索已安装的应用程序 - android.os.TransactionTooLargeException retrieving installed applications 在AsyncTask中使用Gson编写/读取JSON时发生android.os.TransactionTooLargeException - android.os.TransactionTooLargeException occurs when Writing/Reading JSON with Gson in AsyncTask android.os.TransactionTooLargeException:数据包大小NOUGAT错误 - android.os.TransactionTooLargeException: data parcel size NOUGAT ERROR 从 Fragment 移动到 Activity 导致 android.os.TransactionTooLargeException - Move from Fragment to Activity Causes android.os.TransactionTooLargeException android.app.DialogFragment.onStart上的android.os.TransactionTooLargeException - android.os.TransactionTooLargeException at android.app.DialogFragment.onStart 由于java.lang.RuntimeException而在图库中崩溃:android.os.TransactionTooLargeException:数据包大小539544字节 - Crash in gallery due to java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 539544 bytes 碎片化newInstance保存到捆绑的太多数据-android.os.TransactionTooLargeException - Fragment newInstance too much data saved to bundle - android.os.TransactionTooLargeException 调用 TakePicture 时出现 Android TransactionTooLargeException - Android TransactionTooLargeException when calling TakePicture 传递Parcelable ArrayList时,Android TransactionTooLargeException - Android TransactionTooLargeException when passing a Parcelable ArrayList 暂停活动后的TransactionTooLargeException - TransactionTooLargeException when Activity is Paused
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM