2016-12-26 8 views
0

私のコードは、 "xadb-build.apk"という名前の私のアプリケーションをインストールすることになっていますが、何もせず、エラーもなく、強制的に閉じません。ここに私のアプローチsdカードからアプリをインストールするには?

File sdCard = Environment.getExternalStorageDirectory(); 
    String fileStr = sdCard.getAbsolutePath() + "/download";// + 
                  // "app-release.apk"; 

    File file = new File(fileStr, "xadb-build.apk"); 

    if (file.exists()) { 
     try { 
      String command; 
      command = "adb install -r " + file; 
      Process proc = Runtime.getRuntime().exec(
        new String[] { "su", "-c", command }); 
      proc.waitFor(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

} 

私はhereからこのコードを得た(palakの回答を参照してください)

+0

パンクの答えが示唆するコメントの1つとして、 'adb install'の代わりに' pm install'を使ってみましたか? –

+0

'getExternalStorageDirectory();'。これはsdcardではなく外部メモリです。あなたはどこで話していますか? – greenapps

答えて

0

Androidは、このメソッドをサポートしています。

File apkFile = new File({path to APK}); 
     Intent intent = new Intent(Intent.ACTION_VIEW); 
     intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive"); 
     startActivity(intent); 

あなたの方法はお勧めできません。

+0

ルートのみ。ありがとう –

+0

あなたは答えを完了する必要がありますか? –

+0

"あなたは答えを完了しなければなりませんか?" –

関連する問題