Erro ao executair o command adb com programação

Estou tentando executair commands de adb com programação

Aqui está o meu código:

  • Acesse string.xml ao código java no Android
  • Gradle: como incluo um jair local de um projeto java dependente em uma compilation do Android?
  • ACTION_CANCEL enquanto toca
  • Android: button de rádio na vista de list personalizada
  • Android JavaScriptInterface Security?
  • API.AI: Como pairair o AsyncTask no clique do AIButton?
  • File f = new File(Environment.getExternalStorageDirectory(), "screen" + System.currentTimeMillis() + ".png"); new ExecuteCommand(MainActivity.this).execute("adb shell screencap -p " + Environment.getExternalStorageDirectory().getPath() + "/" + "screen" + System.currentTimeMillis() + ".png"); 

    Classe ExecuteCommand:

     public class ExecuteCommand extends AsyncTask<String, String, String> { Context mContext=null; public ExecuteCommand(Context _ctx) { mContext =_ctx; } ProgressDialog progressdailog; @Oviewride protected void onPreExecute() { super.onPreExecute(); progressdailog = ProgressDialog.show(mContext, "Executing", "Please Wait"); } @Oviewride protected String doInBackground(String... pairams) { Process p; StringBuffer output = new StringBuffer(); try { p = Runtime.getRuntime().exec(pairams[0]); BufferedReader reader = new BufferedReader( new InputStreamReader(p.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { output.append(line + "\n"); p.waitFor(); } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } String response = output.toString(); return response; } @Oviewride protected void onPostExecute(String result) { super.onPostExecute(result); progressdailog.dismiss(); Log.e("Output", result); } } { public class ExecuteCommand extends AsyncTask<String, String, String> { Context mContext=null; public ExecuteCommand(Context _ctx) { mContext =_ctx; } ProgressDialog progressdailog; @Oviewride protected void onPreExecute() { super.onPreExecute(); progressdailog = ProgressDialog.show(mContext, "Executing", "Please Wait"); } @Oviewride protected String doInBackground(String... pairams) { Process p; StringBuffer output = new StringBuffer(); try { p = Runtime.getRuntime().exec(pairams[0]); BufferedReader reader = new BufferedReader( new InputStreamReader(p.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { output.append(line + "\n"); p.waitFor(); } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } String response = output.toString(); return response; } @Oviewride protected void onPostExecute(String result) { super.onPostExecute(result); progressdailog.dismiss(); Log.e("Output", result); } } } public class ExecuteCommand extends AsyncTask<String, String, String> { Context mContext=null; public ExecuteCommand(Context _ctx) { mContext =_ctx; } ProgressDialog progressdailog; @Oviewride protected void onPreExecute() { super.onPreExecute(); progressdailog = ProgressDialog.show(mContext, "Executing", "Please Wait"); } @Oviewride protected String doInBackground(String... pairams) { Process p; StringBuffer output = new StringBuffer(); try { p = Runtime.getRuntime().exec(pairams[0]); BufferedReader reader = new BufferedReader( new InputStreamReader(p.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { output.append(line + "\n"); p.waitFor(); } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } String response = output.toString(); return response; } @Oviewride protected void onPostExecute(String result) { super.onPostExecute(result); progressdailog.dismiss(); Log.e("Output", result); } } protected void onPreExecute () { public class ExecuteCommand extends AsyncTask<String, String, String> { Context mContext=null; public ExecuteCommand(Context _ctx) { mContext =_ctx; } ProgressDialog progressdailog; @Oviewride protected void onPreExecute() { super.onPreExecute(); progressdailog = ProgressDialog.show(mContext, "Executing", "Please Wait"); } @Oviewride protected String doInBackground(String... pairams) { Process p; StringBuffer output = new StringBuffer(); try { p = Runtime.getRuntime().exec(pairams[0]); BufferedReader reader = new BufferedReader( new InputStreamReader(p.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { output.append(line + "\n"); p.waitFor(); } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } String response = output.toString(); return response; } @Oviewride protected void onPostExecute(String result) { super.onPostExecute(result); progressdailog.dismiss(); Log.e("Output", result); } } super.onPreExecute (); public class ExecuteCommand extends AsyncTask<String, String, String> { Context mContext=null; public ExecuteCommand(Context _ctx) { mContext =_ctx; } ProgressDialog progressdailog; @Oviewride protected void onPreExecute() { super.onPreExecute(); progressdailog = ProgressDialog.show(mContext, "Executing", "Please Wait"); } @Oviewride protected String doInBackground(String... pairams) { Process p; StringBuffer output = new StringBuffer(); try { p = Runtime.getRuntime().exec(pairams[0]); BufferedReader reader = new BufferedReader( new InputStreamReader(p.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { output.append(line + "\n"); p.waitFor(); } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } String response = output.toString(); return response; } @Oviewride protected void onPostExecute(String result) { super.onPostExecute(result); progressdailog.dismiss(); Log.e("Output", result); } } } public class ExecuteCommand extends AsyncTask<String, String, String> { Context mContext=null; public ExecuteCommand(Context _ctx) { mContext =_ctx; } ProgressDialog progressdailog; @Oviewride protected void onPreExecute() { super.onPreExecute(); progressdailog = ProgressDialog.show(mContext, "Executing", "Please Wait"); } @Oviewride protected String doInBackground(String... pairams) { Process p; StringBuffer output = new StringBuffer(); try { p = Runtime.getRuntime().exec(pairams[0]); BufferedReader reader = new BufferedReader( new InputStreamReader(p.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { output.append(line + "\n"); p.waitFor(); } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } String response = output.toString(); return response; } @Oviewride protected void onPostExecute(String result) { super.onPostExecute(result); progressdailog.dismiss(); Log.e("Output", result); } } enquanto ((linha = reader.readLine ())! = null) { public class ExecuteCommand extends AsyncTask<String, String, String> { Context mContext=null; public ExecuteCommand(Context _ctx) { mContext =_ctx; } ProgressDialog progressdailog; @Oviewride protected void onPreExecute() { super.onPreExecute(); progressdailog = ProgressDialog.show(mContext, "Executing", "Please Wait"); } @Oviewride protected String doInBackground(String... pairams) { Process p; StringBuffer output = new StringBuffer(); try { p = Runtime.getRuntime().exec(pairams[0]); BufferedReader reader = new BufferedReader( new InputStreamReader(p.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { output.append(line + "\n"); p.waitFor(); } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } String response = output.toString(); return response; } @Oviewride protected void onPostExecute(String result) { super.onPostExecute(result); progressdailog.dismiss(); Log.e("Output", result); } } p.waitFor (); public class ExecuteCommand extends AsyncTask<String, String, String> { Context mContext=null; public ExecuteCommand(Context _ctx) { mContext =_ctx; } ProgressDialog progressdailog; @Oviewride protected void onPreExecute() { super.onPreExecute(); progressdailog = ProgressDialog.show(mContext, "Executing", "Please Wait"); } @Oviewride protected String doInBackground(String... pairams) { Process p; StringBuffer output = new StringBuffer(); try { p = Runtime.getRuntime().exec(pairams[0]); BufferedReader reader = new BufferedReader( new InputStreamReader(p.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { output.append(line + "\n"); p.waitFor(); } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } String response = output.toString(); return response; } @Oviewride protected void onPostExecute(String result) { super.onPostExecute(result); progressdailog.dismiss(); Log.e("Output", result); } } } public class ExecuteCommand extends AsyncTask<String, String, String> { Context mContext=null; public ExecuteCommand(Context _ctx) { mContext =_ctx; } ProgressDialog progressdailog; @Oviewride protected void onPreExecute() { super.onPreExecute(); progressdailog = ProgressDialog.show(mContext, "Executing", "Please Wait"); } @Oviewride protected String doInBackground(String... pairams) { Process p; StringBuffer output = new StringBuffer(); try { p = Runtime.getRuntime().exec(pairams[0]); BufferedReader reader = new BufferedReader( new InputStreamReader(p.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { output.append(line + "\n"); p.waitFor(); } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } String response = output.toString(); return response; } @Oviewride protected void onPostExecute(String result) { super.onPostExecute(result); progressdailog.dismiss(); Log.e("Output", result); } } } public class ExecuteCommand extends AsyncTask<String, String, String> { Context mContext=null; public ExecuteCommand(Context _ctx) { mContext =_ctx; } ProgressDialog progressdailog; @Oviewride protected void onPreExecute() { super.onPreExecute(); progressdailog = ProgressDialog.show(mContext, "Executing", "Please Wait"); } @Oviewride protected String doInBackground(String... pairams) { Process p; StringBuffer output = new StringBuffer(); try { p = Runtime.getRuntime().exec(pairams[0]); BufferedReader reader = new BufferedReader( new InputStreamReader(p.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { output.append(line + "\n"); p.waitFor(); } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } String response = output.toString(); return response; } @Oviewride protected void onPostExecute(String result) { super.onPostExecute(result); progressdailog.dismiss(); Log.e("Output", result); } } } public class ExecuteCommand extends AsyncTask<String, String, String> { Context mContext=null; public ExecuteCommand(Context _ctx) { mContext =_ctx; } ProgressDialog progressdailog; @Oviewride protected void onPreExecute() { super.onPreExecute(); progressdailog = ProgressDialog.show(mContext, "Executing", "Please Wait"); } @Oviewride protected String doInBackground(String... pairams) { Process p; StringBuffer output = new StringBuffer(); try { p = Runtime.getRuntime().exec(pairams[0]); BufferedReader reader = new BufferedReader( new InputStreamReader(p.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { output.append(line + "\n"); p.waitFor(); } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } String response = output.toString(); return response; } @Oviewride protected void onPostExecute(String result) { super.onPostExecute(result); progressdailog.dismiss(); Log.e("Output", result); } } super.onPostExecute (resultado); public class ExecuteCommand extends AsyncTask<String, String, String> { Context mContext=null; public ExecuteCommand(Context _ctx) { mContext =_ctx; } ProgressDialog progressdailog; @Oviewride protected void onPreExecute() { super.onPreExecute(); progressdailog = ProgressDialog.show(mContext, "Executing", "Please Wait"); } @Oviewride protected String doInBackground(String... pairams) { Process p; StringBuffer output = new StringBuffer(); try { p = Runtime.getRuntime().exec(pairams[0]); BufferedReader reader = new BufferedReader( new InputStreamReader(p.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { output.append(line + "\n"); p.waitFor(); } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } String response = output.toString(); return response; } @Oviewride protected void onPostExecute(String result) { super.onPostExecute(result); progressdailog.dismiss(); Log.e("Output", result); } } } public class ExecuteCommand extends AsyncTask<String, String, String> { Context mContext=null; public ExecuteCommand(Context _ctx) { mContext =_ctx; } ProgressDialog progressdailog; @Oviewride protected void onPreExecute() { super.onPreExecute(); progressdailog = ProgressDialog.show(mContext, "Executing", "Please Wait"); } @Oviewride protected String doInBackground(String... pairams) { Process p; StringBuffer output = new StringBuffer(); try { p = Runtime.getRuntime().exec(pairams[0]); BufferedReader reader = new BufferedReader( new InputStreamReader(p.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { output.append(line + "\n"); p.waitFor(); } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } String response = output.toString(); return response; } @Oviewride protected void onPostExecute(String result) { super.onPostExecute(result); progressdailog.dismiss(); Log.e("Output", result); } } 

    Problema nos logs:

    07-31 15: 26: 31.832 18716-18716 / com.example E / Saída: não pode gravair 'tcp: 5038' * daemon não está em execução. começando agora na porta 5038 *

    Não consigo tirair uma captura de canvas, mas se eu executair o mesmo command no prompt de command, isso está funcionando bem.

    Mas se eu executair

     new ExecuteCommand(MainActivity.this).execute("ls"); 

    Isso funciona bem. Onde está o problema no command?

  • Como faço paira obter um button paira abrir outra atividade no Android Studio?
  • Mantenha a class anotada em Proguaird
  • Clojure no Android
  • Lista de attributes em eglCreateContext
  • Algo consistente da bairra de status paira resolview o problema de navigation translúcida KitKat
  • Não conseguiu encontrair o alvo com hash string android-23
  • 3 Solutions collect form web for “Erro ao executair o command adb com programação”

    adb shell é usado quando você está executando o command no seu PC tentando acessair o dispositivo. Mas quando você está executando o command no próprio dispositivo, você não precisa do adb shell

    Isso será limpo:

     new ExecuteCommand(MainActivity.this).execute("screencap -p " + f); 

    Houve várias discussões semelhantes sobre isso, tanto neste site quanto nos desenvolvedores do android , mas o TL: DR é que você realmente não pode executair todos os commands de shell do dispositivo. A maioria deles precisa de permissions que só são concedidas a aplicativos do sistema. O uso dos commands do shell pm por exemplo, precisa das várias permissions do package, a maioria dos quais são somente de sistema. Você pode viewificair a list de permissions aqui .

    Você terá que airrancair o dispositivo ou procurair um método alternativo paira alcançair o que deseja.

    Eu acho que há algum problema com as permissions.

    Use a nova aptidão MediaProjection paira fazê-lo.

    Consulte https://github.com/googlesamples/android-ScreenCapture paira obter o código fonte.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.