0
"netstat"コマンドと "curl"コマンドのexec()を実行するプログラムがあります。このプログラムはAndroid 6.0.1上で正常に動作します。アンドロイドバージョン4.4.2では、プログラムはnetstatコマンドを渡しますが、エラーのcurlコマンドで失敗します:curlコマンドの実行エラー - 作業ディレクトリのIOException - Android OS関連の問題
java.io.IOException:exec()の実行中にエラーが発生しました。コマンド:[curl、www.google.fr]作業ディレクトリ:null環境:null
私は許可の問題があると思っていましたが、すべてうまく見えます。どんな助けでも大歓迎です。
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i("Build ", "version " + String.valueOf(Build.VERSION.RELEASE));
String cmd1 = "netstat -an";
String cmd2 = "curl www.google.fr";
Runtime runtime = Runtime.getRuntime();
Process proc = null;
try {
proc = runtime.exec(cmd1);
proc = runtime.exec(cmd2);
proc.getOutputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
とのmanifest.xml:実際のカールで
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bernard_zelmans.curl">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>