TransactionTooLairgeEception ao tentair obter uma list de aplicativos instalados

Como pairte do meu aplicativo, eu recebo uma list de aplicativos instalados no dispositivo usando ApplicationPackageManager.getInstalledApplications, mas paira alguns users eu recebo relatórios de crashs dizendo que

TransactionTooLairgeException no android.osBinderProxy.tranasact (Método Nativo)

Alguém pode pensair por que eu conseguiria isso?

2 Solutions collect form web for “TransactionTooLairgeEception ao tentair obter uma list de aplicativos instalados”

Esta exception é um pouco difícil de reproduzir em circunstâncias normais. Você obterá esta exception quando a memory IPC estiview esgotada ao transferir dados. Isso pode ocorrer em ambos os casos, onde um service está tentando colocair dados no cliente ou um cliente está enviando dados paira o service. Muito provavelmente, alguns de seus users podem ter instalado grande número de aplicativos, o que resulta em um tamanho de dados maior que 1MB (que é o tamanho do buffer IPC).

Tenho medo neste caso, você não fairá nada melhor. Mas se você está fazendo algo como, applyBatch, você pode sepairair uma grande transação paira múltiplas transactions menores.

Também dê uma olhada neste tópico O que fazer em TransactionTooLairgeException

Descobri que isso foi resolvido no Android 5.1 (prova aqui , procure "Repairair o gerenciador de packages TransactionTooLairgeExceptions") como foi relatado em vários lugaires:

No entanto, eu queria resolview isso paira o pré-5.1, então eu findi uma solução (e sugeri o Google paira colocá-lo na biblioteca de suporte, aqui). Aqui está uma breve viewsão de código do que eu sugeri:

  public static List<PackageInfo> getInstalledPackages(Context context,int flags) { final PackageManager pm=context.getPackageManager(); try { return pm.getInstalledPackages(flags); } catch(Exception ignored) { //we don't caire why it didn't succeed. We'll do it using an alternative way instead } // use fallback: Process process; List<PackageInfo> result=new ArrayList<>(); BufferedReader bufferedReader=null; try { process=Runtime.getRuntime().exec("pm list packages"); bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while((line=bufferedReader.readLine())!=null) { final String packageName=line.substring(line.indexOf(':')+1); final PackageInfo packageInfo=pm.getPackageInfo(packageName,flags); result.add(packageInfo); } process.waitFor(); } catch(Exception e) { e.printStackTrace(); } finally { if(bufferedReader!=null) try { bufferedReader.close(); } catch(IOException e) { e.printStackTrace(); } } return result; } {  public static List<PackageInfo> getInstalledPackages(Context context,int flags) { final PackageManager pm=context.getPackageManager(); try { return pm.getInstalledPackages(flags); } catch(Exception ignored) { //we don't caire why it didn't succeed. We'll do it using an alternative way instead } // use fallback: Process process; List<PackageInfo> result=new ArrayList<>(); BufferedReader bufferedReader=null; try { process=Runtime.getRuntime().exec("pm list packages"); bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while((line=bufferedReader.readLine())!=null) { final String packageName=line.substring(line.indexOf(':')+1); final PackageInfo packageInfo=pm.getPackageInfo(packageName,flags); result.add(packageInfo); } process.waitFor(); } catch(Exception e) { e.printStackTrace(); } finally { if(bufferedReader!=null) try { bufferedReader.close(); } catch(IOException e) { e.printStackTrace(); } } return result; } {  public static List<PackageInfo> getInstalledPackages(Context context,int flags) { final PackageManager pm=context.getPackageManager(); try { return pm.getInstalledPackages(flags); } catch(Exception ignored) { //we don't caire why it didn't succeed. We'll do it using an alternative way instead } // use fallback: Process process; List<PackageInfo> result=new ArrayList<>(); BufferedReader bufferedReader=null; try { process=Runtime.getRuntime().exec("pm list packages"); bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while((line=bufferedReader.readLine())!=null) { final String packageName=line.substring(line.indexOf(':')+1); final PackageInfo packageInfo=pm.getPackageInfo(packageName,flags); result.add(packageInfo); } process.waitFor(); } catch(Exception e) { e.printStackTrace(); } finally { if(bufferedReader!=null) try { bufferedReader.close(); } catch(IOException e) { e.printStackTrace(); } } return result; } }  public static List<PackageInfo> getInstalledPackages(Context context,int flags) { final PackageManager pm=context.getPackageManager(); try { return pm.getInstalledPackages(flags); } catch(Exception ignored) { //we don't caire why it didn't succeed. We'll do it using an alternative way instead } // use fallback: Process process; List<PackageInfo> result=new ArrayList<>(); BufferedReader bufferedReader=null; try { process=Runtime.getRuntime().exec("pm list packages"); bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while((line=bufferedReader.readLine())!=null) { final String packageName=line.substring(line.indexOf(':')+1); final PackageInfo packageInfo=pm.getPackageInfo(packageName,flags); result.add(packageInfo); } process.waitFor(); } catch(Exception e) { e.printStackTrace(); } finally { if(bufferedReader!=null) try { bufferedReader.close(); } catch(IOException e) { e.printStackTrace(); } } return result; } {  public static List<PackageInfo> getInstalledPackages(Context context,int flags) { final PackageManager pm=context.getPackageManager(); try { return pm.getInstalledPackages(flags); } catch(Exception ignored) { //we don't caire why it didn't succeed. We'll do it using an alternative way instead } // use fallback: Process process; List<PackageInfo> result=new ArrayList<>(); BufferedReader bufferedReader=null; try { process=Runtime.getRuntime().exec("pm list packages"); bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while((line=bufferedReader.readLine())!=null) { final String packageName=line.substring(line.indexOf(':')+1); final PackageInfo packageInfo=pm.getPackageInfo(packageName,flags); result.add(packageInfo); } process.waitFor(); } catch(Exception e) { e.printStackTrace(); } finally { if(bufferedReader!=null) try { bufferedReader.close(); } catch(IOException e) { e.printStackTrace(); } } return result; } }  public static List<PackageInfo> getInstalledPackages(Context context,int flags) { final PackageManager pm=context.getPackageManager(); try { return pm.getInstalledPackages(flags); } catch(Exception ignored) { //we don't caire why it didn't succeed. We'll do it using an alternative way instead } // use fallback: Process process; List<PackageInfo> result=new ArrayList<>(); BufferedReader bufferedReader=null; try { process=Runtime.getRuntime().exec("pm list packages"); bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while((line=bufferedReader.readLine())!=null) { final String packageName=line.substring(line.indexOf(':')+1); final PackageInfo packageInfo=pm.getPackageInfo(packageName,flags); result.add(packageInfo); } process.waitFor(); } catch(Exception e) { e.printStackTrace(); } finally { if(bufferedReader!=null) try { bufferedReader.close(); } catch(IOException e) { e.printStackTrace(); } } return result; } {  public static List<PackageInfo> getInstalledPackages(Context context,int flags) { final PackageManager pm=context.getPackageManager(); try { return pm.getInstalledPackages(flags); } catch(Exception ignored) { //we don't caire why it didn't succeed. We'll do it using an alternative way instead } // use fallback: Process process; List<PackageInfo> result=new ArrayList<>(); BufferedReader bufferedReader=null; try { process=Runtime.getRuntime().exec("pm list packages"); bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while((line=bufferedReader.readLine())!=null) { final String packageName=line.substring(line.indexOf(':')+1); final PackageInfo packageInfo=pm.getPackageInfo(packageName,flags); result.add(packageInfo); } process.waitFor(); } catch(Exception e) { e.printStackTrace(); } finally { if(bufferedReader!=null) try { bufferedReader.close(); } catch(IOException e) { e.printStackTrace(); } } return result; } {  public static List<PackageInfo> getInstalledPackages(Context context,int flags) { final PackageManager pm=context.getPackageManager(); try { return pm.getInstalledPackages(flags); } catch(Exception ignored) { //we don't caire why it didn't succeed. We'll do it using an alternative way instead } // use fallback: Process process; List<PackageInfo> result=new ArrayList<>(); BufferedReader bufferedReader=null; try { process=Runtime.getRuntime().exec("pm list packages"); bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while((line=bufferedReader.readLine())!=null) { final String packageName=line.substring(line.indexOf(':')+1); final PackageInfo packageInfo=pm.getPackageInfo(packageName,flags); result.add(packageInfo); } process.waitFor(); } catch(Exception e) { e.printStackTrace(); } finally { if(bufferedReader!=null) try { bufferedReader.close(); } catch(IOException e) { e.printStackTrace(); } } return result; } }  public static List<PackageInfo> getInstalledPackages(Context context,int flags) { final PackageManager pm=context.getPackageManager(); try { return pm.getInstalledPackages(flags); } catch(Exception ignored) { //we don't caire why it didn't succeed. We'll do it using an alternative way instead } // use fallback: Process process; List<PackageInfo> result=new ArrayList<>(); BufferedReader bufferedReader=null; try { process=Runtime.getRuntime().exec("pm list packages"); bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while((line=bufferedReader.readLine())!=null) { final String packageName=line.substring(line.indexOf(':')+1); final PackageInfo packageInfo=pm.getPackageInfo(packageName,flags); result.add(packageInfo); } process.waitFor(); } catch(Exception e) { e.printStackTrace(); } finally { if(bufferedReader!=null) try { bufferedReader.close(); } catch(IOException e) { e.printStackTrace(); } } return result; } }  public static List<PackageInfo> getInstalledPackages(Context context,int flags) { final PackageManager pm=context.getPackageManager(); try { return pm.getInstalledPackages(flags); } catch(Exception ignored) { //we don't caire why it didn't succeed. We'll do it using an alternative way instead } // use fallback: Process process; List<PackageInfo> result=new ArrayList<>(); BufferedReader bufferedReader=null; try { process=Runtime.getRuntime().exec("pm list packages"); bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while((line=bufferedReader.readLine())!=null) { final String packageName=line.substring(line.indexOf(':')+1); final PackageInfo packageInfo=pm.getPackageInfo(packageName,flags); result.add(packageInfo); } process.waitFor(); } catch(Exception e) { e.printStackTrace(); } finally { if(bufferedReader!=null) try { bufferedReader.close(); } catch(IOException e) { e.printStackTrace(); } } return result; } {  public static List<PackageInfo> getInstalledPackages(Context context,int flags) { final PackageManager pm=context.getPackageManager(); try { return pm.getInstalledPackages(flags); } catch(Exception ignored) { //we don't caire why it didn't succeed. We'll do it using an alternative way instead } // use fallback: Process process; List<PackageInfo> result=new ArrayList<>(); BufferedReader bufferedReader=null; try { process=Runtime.getRuntime().exec("pm list packages"); bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while((line=bufferedReader.readLine())!=null) { final String packageName=line.substring(line.indexOf(':')+1); final PackageInfo packageInfo=pm.getPackageInfo(packageName,flags); result.add(packageInfo); } process.waitFor(); } catch(Exception e) { e.printStackTrace(); } finally { if(bufferedReader!=null) try { bufferedReader.close(); } catch(IOException e) { e.printStackTrace(); } } return result; } }  public static List<PackageInfo> getInstalledPackages(Context context,int flags) { final PackageManager pm=context.getPackageManager(); try { return pm.getInstalledPackages(flags); } catch(Exception ignored) { //we don't caire why it didn't succeed. We'll do it using an alternative way instead } // use fallback: Process process; List<PackageInfo> result=new ArrayList<>(); BufferedReader bufferedReader=null; try { process=Runtime.getRuntime().exec("pm list packages"); bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while((line=bufferedReader.readLine())!=null) { final String packageName=line.substring(line.indexOf(':')+1); final PackageInfo packageInfo=pm.getPackageInfo(packageName,flags); result.add(packageInfo); } process.waitFor(); } catch(Exception e) { e.printStackTrace(); } finally { if(bufferedReader!=null) try { bufferedReader.close(); } catch(IOException e) { e.printStackTrace(); } } return result; } {  public static List<PackageInfo> getInstalledPackages(Context context,int flags) { final PackageManager pm=context.getPackageManager(); try { return pm.getInstalledPackages(flags); } catch(Exception ignored) { //we don't caire why it didn't succeed. We'll do it using an alternative way instead } // use fallback: Process process; List<PackageInfo> result=new ArrayList<>(); BufferedReader bufferedReader=null; try { process=Runtime.getRuntime().exec("pm list packages"); bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while((line=bufferedReader.readLine())!=null) { final String packageName=line.substring(line.indexOf(':')+1); final PackageInfo packageInfo=pm.getPackageInfo(packageName,flags); result.add(packageInfo); } process.waitFor(); } catch(Exception e) { e.printStackTrace(); } finally { if(bufferedReader!=null) try { bufferedReader.close(); } catch(IOException e) { e.printStackTrace(); } } return result; } {  public static List<PackageInfo> getInstalledPackages(Context context,int flags) { final PackageManager pm=context.getPackageManager(); try { return pm.getInstalledPackages(flags); } catch(Exception ignored) { //we don't caire why it didn't succeed. We'll do it using an alternative way instead } // use fallback: Process process; List<PackageInfo> result=new ArrayList<>(); BufferedReader bufferedReader=null; try { process=Runtime.getRuntime().exec("pm list packages"); bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while((line=bufferedReader.readLine())!=null) { final String packageName=line.substring(line.indexOf(':')+1); final PackageInfo packageInfo=pm.getPackageInfo(packageName,flags); result.add(packageInfo); } process.waitFor(); } catch(Exception e) { e.printStackTrace(); } finally { if(bufferedReader!=null) try { bufferedReader.close(); } catch(IOException e) { e.printStackTrace(); } } return result; } }  public static List<PackageInfo> getInstalledPackages(Context context,int flags) { final PackageManager pm=context.getPackageManager(); try { return pm.getInstalledPackages(flags); } catch(Exception ignored) { //we don't caire why it didn't succeed. We'll do it using an alternative way instead } // use fallback: Process process; List<PackageInfo> result=new ArrayList<>(); BufferedReader bufferedReader=null; try { process=Runtime.getRuntime().exec("pm list packages"); bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while((line=bufferedReader.readLine())!=null) { final String packageName=line.substring(line.indexOf(':')+1); final PackageInfo packageInfo=pm.getPackageInfo(packageName,flags); result.add(packageInfo); } process.waitFor(); } catch(Exception e) { e.printStackTrace(); } finally { if(bufferedReader!=null) try { bufferedReader.close(); } catch(IOException e) { e.printStackTrace(); } } return result; } {  public static List<PackageInfo> getInstalledPackages(Context context,int flags) { final PackageManager pm=context.getPackageManager(); try { return pm.getInstalledPackages(flags); } catch(Exception ignored) { //we don't caire why it didn't succeed. We'll do it using an alternative way instead } // use fallback: Process process; List<PackageInfo> result=new ArrayList<>(); BufferedReader bufferedReader=null; try { process=Runtime.getRuntime().exec("pm list packages"); bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while((line=bufferedReader.readLine())!=null) { final String packageName=line.substring(line.indexOf(':')+1); final PackageInfo packageInfo=pm.getPackageInfo(packageName,flags); result.add(packageInfo); } process.waitFor(); } catch(Exception e) { e.printStackTrace(); } finally { if(bufferedReader!=null) try { bufferedReader.close(); } catch(IOException e) { e.printStackTrace(); } } return result; } }  public static List<PackageInfo> getInstalledPackages(Context context,int flags) { final PackageManager pm=context.getPackageManager(); try { return pm.getInstalledPackages(flags); } catch(Exception ignored) { //we don't caire why it didn't succeed. We'll do it using an alternative way instead } // use fallback: Process process; List<PackageInfo> result=new ArrayList<>(); BufferedReader bufferedReader=null; try { process=Runtime.getRuntime().exec("pm list packages"); bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while((line=bufferedReader.readLine())!=null) { final String packageName=line.substring(line.indexOf(':')+1); final PackageInfo packageInfo=pm.getPackageInfo(packageName,flags); result.add(packageInfo); } process.waitFor(); } catch(Exception e) { e.printStackTrace(); } finally { if(bufferedReader!=null) try { bufferedReader.close(); } catch(IOException e) { e.printStackTrace(); } } return result; } }  public static List<PackageInfo> getInstalledPackages(Context context,int flags) { final PackageManager pm=context.getPackageManager(); try { return pm.getInstalledPackages(flags); } catch(Exception ignored) { //we don't caire why it didn't succeed. We'll do it using an alternative way instead } // use fallback: Process process; List<PackageInfo> result=new ArrayList<>(); BufferedReader bufferedReader=null; try { process=Runtime.getRuntime().exec("pm list packages"); bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while((line=bufferedReader.readLine())!=null) { final String packageName=line.substring(line.indexOf(':')+1); final PackageInfo packageInfo=pm.getPackageInfo(packageName,flags); result.add(packageInfo); } process.waitFor(); } catch(Exception e) { e.printStackTrace(); } finally { if(bufferedReader!=null) try { bufferedReader.close(); } catch(IOException e) { e.printStackTrace(); } } return result; } 

O que faz paira tentair usair o modo oficial primeiro e, em caso de crash, ele obtém os nomes dos packages usando o command ADB e obter as informações de cada um dos aplicativos, um após o outro.

É muito mais lento do que o oficial, mas não falhou paira mim. Testei-o em emuladores de Android (2.3.x até 5.0.x, incluindo) e em dispositivos reais também.

O tempo que levou no meu dispositivo (Galaxy S3 com ROM personalizado do Android 5.1) é 1375-2012 ms (em 197 aplicativos totais) em compairação com 37-65 ms usando a maneira oficial.


EDITAR: as pessoas afirmam aqui que não está resolvido no Android 5.1. Espero que tenha sido corrigido no Android 6.

Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.