繁体   English   中英

执行queryIntentActivities时android.os.TransactionTooLargeException

[英]android.os.TransactionTooLargeException when executing queryIntentActivities

我在Android 5.0.1上使用设备,并且在执行该功能时:

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

引发了TransactionTooLargeException类型的异常....我不能使用标志:MATCH_DEFAULT_ONLY,因为我不仅限于支持CATEGORY_DEFAULT的那些活动。 看起来问题与返回的数据量有关,就像我在stackoverflow上发现的许多相关问题一样……有没有办法打破这种反应? 还是存在一个查询,等效查询或标志的组合,这些查询允许通过多个查询获得相同的结果? 我问是因为我不清楚文档中flag = 0的含义: https : //developer.android.com/reference/android/content/pm/PackageManager.html#queryIntentActivities(android.content.Intent ,int)

可能我可以使用不同的查询多次查询并合并结果吗?

您可以通过更加具体地构造Intent来对查询进行分块,并执行多个查询,而不是一次总付查询。 现在,您正在查询设备上的每个应用程序(可能每个应用程序可能多个)(因为所有可以启动的应用程序都会有一个android.app.action.Main操作),该操作遍历了〜1 MB共享缓冲区的分配包裹限制导致异常:

从文档:

{ 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.

因此,添加类别会缩小搜索结果的范围。 如果您需要动作类型为“ 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)
   }
}

您可能还应该尝试捕获,因为在执行MATCH_ALL时,仍然不能保证查询不会太大。 可能有适当的标志可以帮助您解决此问题,但是我对您的用例不熟悉。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM