2
votes

I have an executable called iperf to measure network speed. The executable is an asset which I copy to my app files dir programatically. After that, I execute chmod command with 777 permission over this executable, with:

val processChmod = Runtime.getRuntime().exec("/system/bin/chmod 777 
${getExternalFilesDir(null)}/iperf3")
processChmod.waitFor()

The command finishes with exit code 0.

Then, I invoke this executable with:

ProcessBuilder().command(command).redirectErrorStream(true).start()

And I get this:

Cannot run program "/storage/emulated/0/Android/data/my.packpage.name/files/iperf3": error=13, Permission denied

I don't know what can I do to execute this command in my app files folder. I also have the write permission in my manifest:

  <uses-permission 
  android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

And the app has the write permission granted.

2
Did you find the solution? - osyan

2 Answers

0
votes

If your intention is to measure network speed, you can do so pretty easily by using Connectivity Manager.

    ConnectivityManager cm = (ConnectivityManager) 
    context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    NetworkCapabilities nc = cm.getNetworkCapabilities(cm.getActiveNetwork());
    int downSpeed = nc.getLinkDownstreamBandwidthKbps();
    int upSpeed = nc.getLinkUpstreamBandwidthKbps();
0
votes

You need root access for exec() if permission is denied. Use NetworkCapabilities instead.