3

Androidターミナルエミュレータでコマンドを実行しようとしています。デバイスをルート化し、 superuser.apkをインストールしました。

私はこのようにやっています:

    try {
        Process process = Runtime.getRuntime().exec(cmd);
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String line = bufferedReader.readLine();
        while ( line != null ) {
            Log.i("SHELL", line);
            line = bufferedReader.readLine();
        }
    } catch ( Exception e) {
        e.printStackTrace();
    }

そしてまたよく:

    try {
        Process process = Runtime.getRuntime().exec(<b>cmd</b>*);
        process.waitFor();
    } catch ( Exception e ){
        e.printStackTrace();
    }

をインストールしようとしています。コードによるAPK。私は次のことを試しました:

cmd =>pm install /mnt/sdcard/app.apk 結果なし。

cmd =>su -c "pm install /mnt/sdcard/app.apk" 一重引用符、二重引用符、引用符なし。結果:

    I/SHELL(1432): Usage: su [options] [LOGIN]

    I/SHELL(1432): Options:
    I/SHELL(1432):   -c, --command COMMAND         pass COMMAND to the invoked shell
    I/SHELL(1432):   -h, --help                    display this help message and exit
    I/SHELL(1432):   -, -l, --login                make the shell a login shell
    I/SHELL(1432):   -s, --shell SHELL             use SHELL instead of the default in passwd
    I/SHELL(1432):   -v, --version                 display version number and exit
    I/SHELL(1432):   -V                            display version code and exit. this is
    I/SHELL(1432):                                 used almost exclusively by Superuser.apk

lsのような他のコマンドは正常に実行されます。

/ mnt / sdcardにあるapkをインストールするにはどうすればよいですか?

ありがとう!

4

3 に答える 3

4

これを試して :

su -c "pm install /mnt/sdcard/app.apk" root

しかし、電話をルート化していないと機能しないと思います

于 2012-07-19T11:25:18.453 に答える
3

解決策を見つけました。

    Process p;  
    try {  
            // Preform su to get root privledges  
            p = Runtime.getRuntime().exec("su");   

            // Attempt to write a file to a root-only  
            DataOutputStream os = new DataOutputStream(p.getOutputStream());  
            os.writeBytes(**any command**+"\n");  

            // Close the terminal  
            os.writeBytes("exit\n");  
            os.flush();  
            try {  
                    p.waitFor();
                    if (p.exitValue() != 255) {  
                            // Sucess :-)
                    }  
                    else {  
                           // Fail
                    }  

            } catch (InterruptedException e) {  
                    // Fail
            }  
    } catch (IOException e) {  
            // Fail
    } 

皆さんありがとう!

于 2012-07-20T07:48:47.963 に答える
0

コマンドを実行しているとき、ADBシェルではなく、アプリケーションのシェル環境であることに疑問があります。

コードから:(インテントでやりたい場合)

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(path+"/<application_name>.apk")), "application/vnd.android.package-archive");
startActivity(intent);

そして、これは許可です..

<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
于 2012-07-19T11:25:49.930 に答える