如何从adb shell中启动应用程序

如何从adb shell中启动应用程序,第1张

adb shell 中的am start参数用于启动设备上的对应应用,具体用法为:

首先连上设备后adb shell进入交互模式,然后am start 包名/.launch activity 例如:am start com.example/.activity.WelcomActivity

可以直接adb shell am start com.example/.activity.WelcomActivity

android程序执行adbshell命令(实例源码)packagenet.gimite.nativeexeimportjava.io.BufferedReaderimportjava.io.FileOutputStreamimportjava.io.IOExceptionimportjava.io.InputStreamimportjava.io.InputStreamReaderimportjava.net.HttpURLConnectionimportjava.net.MalformedURLExceptionimportjava.net.URLimportnet.gimite.nativeexe.Rimportandroid.app.Activityimportandroid.os.Bundleimportandroid.os.Handlerimportandroid.view.Viewimportandroid.view.View.OnClickListenerimportandroid.widget.*publicclassMainActivityextendsActivity{privateTextViewoutputViewprivateButtonlocalRunButtonprivateEditTextlocalPathEditprivateHandlerhandler=newHandler()privateEditTexturlEditprivateButtonremoteRunButton/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState)setContentView(R.layout.main)outputView=(TextView)findViewById(R.id.outputView)localPathEdit=(EditText)findViewById(R.id.localPathEdit)localRunButton=(Button)findViewById(R.id.localRunButton)localRunButton.setOnClickListener(onLocalRunButtonClick)}privateOnClickListeneronLocalRunButtonClick=newOnClickListener(){publicvoidonClick(Viewv){Stringoutput=exec(localPathEdit.getText().toString())output(output)//try{//////Processprocess=Runtime.getRuntime().exec(localPathEdit.getText().toString())////}catch(IOExceptione){////TODOAuto-generatedcatchblock//e.printStackTrace()//}}}//ExecutesUNIXcommand.privateStringexec(Stringcommand){try{Processprocess=Runtime.getRuntime().exec(command)BufferedReaderreader=newBufferedReader(newInputStreamReader(process.getInputStream()))intreadchar[]buffer=newchar[4096]StringBufferoutput=newStringBuffer()while((read=reader.read(buffer))>0){output.append(buffer,0,read)}reader.close()process.waitFor()returnoutput.toString()}catch(IOExceptione){thrownewRuntimeException(e)}catch(InterruptedExceptione){thrownewRuntimeException(e)}}privatevoiddownload(StringurlStr,StringlocalPath){try{URLurl=newURL(urlStr)HttpURLConnectionurlconn=(HttpURLConnection)url.openConnection()urlconn.setRequestMethod("GET")urlconn.setInstanceFollowRedirects(true)urlconn.connect()InputStreamin=urlconn.getInputStream()FileOutputStreamout=newFileOutputStream(localPath)intreadbyte[]buffer=newbyte[4096]while((read=in.read(buffer))>0){out.write(buffer,0,read)}out.close()in.close()urlconn.disconnect()}catch(MalformedURLExceptione){thrownewRuntimeException(e)}catch(IOExceptione){thrownewRuntimeException(e)}}privatevoidoutput(finalStringstr){Runnableproc=newRunnable(){publicvoidrun(){outputView.setText(str)}}handler.post(proc)}}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7766962.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-09
下一篇 2023-04-09

发表评论

登录后才能评论

评论列表(0条)

保存