2017-10-24 10 views
0

programitically私はスタックとAPKをインストールするには、以下の方法を見つけるために検索が、それ は、Android API 6上では正常に動作し、「このメソッドは、実行 携帯電話の画面上でこのエラーが現れなるhigher.whenしないインストールあり パッケージを解析する問題です "誰でも助けてくれますか?APKダウンロード

Intent intent = new Intent(Intent.ACTION_VIEW); 
      Uri uri = Uri.fromFile(new File(PathManagers.getApk(context) + zipFileNameUnzipApk)); 
      intent.setDataAndType(uri, "application/vnd.android.package-archive"); 

      if (intent.resolveActivityInfo(context.getPackageManager(), 0) != null) 
      { 
       context.startActivity(intent); 
      } 
      else 
      { 

       // if you reach this place, it means there is no any file 
       // explorer app installed on your device 
      } 
+1

を使用し、その後根ざしている場合は? – ruben

+0

あなたの質問を編集して、「正しく動作しない」ということを詳しく説明してください。 Android 7.0以降のデバイスでは 'Uri.fromFile()'を使用できません(ファイルを提供するには 'FileProvider'を使う必要があります)。また、 'ACTION_VIEW'ではなく' ACTION_INSTALL_PACKAGE'を使う方が良いでしょう。 – CommonsWare

答えて

0

お使いのデバイスがこの方法の問題は、あなたが持っているされているものを

 private void installApk(String filename) { 
    File file = new File(filename); 
    if (file.exists()) { 
     try { 
      //final String command = " pm install -r " + file.getAbsolutePath(); 
      final String command = "pm install -r " + file.getAbsolutePath(); 

      //Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", command }); 
      Process proc = Runtime.getRuntime().exec(command); 
      proc.waitFor(); 
     } catch (Exception e) { 
      ProjectUtils.PSLogger(TAG, "error while installation of apk"); 
      e.printStackTrace(); 
     } 
    } 
} 
+0

質問に根ざしたデバイスフレーズを使用したことはありませんでしたが、あなたの答えがありがとう –

関連する問題