Command line in appium

I use terminal to run this command, it’s worked
adb devices | awk 'NR>1{print $1}' | xargs -n1 -I% adb -s % -d shell pm grant com.zing.zalo android.permission.RECEIVE_SMS

but use code to run, it’s not worked
cmd.runCommand("adb devices | awk 'NR>1{print $1}' | xargs -n1 -I% adb -s % -d shell pm grant com.zing.zalo android.permission.RECEIVE_SMS");

please help me

OS: Mac
Appium Version: 1.6.5
Platform: android

why you do not grand permission at driver start with capability:

capabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, "true");

hi, @Aleksei
Because I have a testcase need to clear app data
after clear appdata, it must be grant permission again

if you need to clear app data on Android you just need to open driver with correct capabilities. check -> Different capabilities for different scenarios

and to add permissions after reset add above capability to driver also thus you reset app and grand permission right on driver start.

Dear @Aleksei, this capability in which appium version, I cannot find it in 1.6.5?

@lehungcuong - https://github.com/appium/java-client/releases -> see v5.0.0-BETA8