About Android root over phone silent installation and uninstallation

Source: Internet
Author: User

Use a tool class Androidcommon learn more about address: http://www.open-open.com/lib/view/open1385174381198.html, It provides us with a silent installation of the tool class Packageutils, which contains installation and uninstallation.

Go down the train of thought, the first silent installation to use the adb command, so the phone must be root (as for 360 mobile phone assistant silent installation, no root can be installed silently, specifically I do not know, which Daniel clearly hope to explore), in the ADB command to execute PM install-r can, Refer to the classes provided by Androidcommon for details. Tool Class Packageutil.sinstallsilent (context, path) silent installation and packageutil.uninstallsilent (this, path) silently unload, all have the return value, A return value of 1 indicates a success, and the exact return value of the PackageUtil is not much to say if the return value is not 1, you can perform a normal installation method, then see the code

Only the Androidcommon tool class is packaged in the demo to Lib, can directly see the source code

Demo http://download.csdn.net/detail/u012303938/8679791

The APK in the Mainactivity.class code may expire, and if it can't be downloaded, change the APK

Package Com.example.update;import Java.io.file;import Java.io.fileoutputstream;import java.io.IOException;import Java.io.inputstream;import Org.apache.http.httpentity;import Org.apache.http.httpresponse;import Org.apache.http.client.clientprotocolexception;import Org.apache.http.client.httpclient;import Org.apache.http.client.methods.httpget;import Org.apache.http.impl.client.defaulthttpclient;import Cn.trinea.android.common.util.packageutils;import Android.app.activity;import Android.content.Intent;import Android.net.uri;import Android.os.bundle;import Android.os.environment;import Android.os.Handler;import Android.os.message;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.Button ; Import Android.widget.textview;import Android.widget.toast;public class Mainactivity extends Activity{private int Percent;private Button button1,button2;private TextView textView1; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {//TODO auto-generated method Stubsuper.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); button1= (Button) findViewById ( R.id.button1); button2= (Button) Findviewbyid (R.id.button2); textview1= (TextView) Findviewbyid (R.ID.TEXTVIEW1); Button1.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO auto-generated Method Stubloadapks ();}}); Button2.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO auto-generated Method Stubint L=packageutils.uninstallsilent (Mainactivity.this, "Com.example.callphone");              if (l!=1) {Uri Packageuri = Uri.parse ("Package:" + "Com.example.callphone");              Intent uninstallintent = new Intent (Intent.action_delete,packageuri);              Uninstallintent.setflags (Intent.flag_activity_new_task); StartActivity (uninstallintent); }}});} private void Loadapks () {//TODO auto-generated method Stubnew Thread () {public void run () {HttpClient client=new defaultht Tpclient (); String url= "http://121.42.15.80:800/CALLPHONE.APK "; HttpGet get=new httpget (URL);; HttpResponse response=null;try {response=client.execute (GET); Httpentity entity=response.getentity (); Long length=entity.getcontentlength (); int Count=0;inputstream is= Entity.getcontent (); FileOutputStream outputstream=null;if (is!=null) {file File=new file (Environment.getexternalstoragedirectory (), " ybds.apk "); outputstream=new fileoutputstream (file); byte[] Bt=new byte[1024];int len=-1;while ((Len=is.read (BT))!=-1 {outputstream.write (BT, 0, Len), count+=len;if ((int) count*100/length>percent) {percent= (int) (100*count/length) ;((Activity) mainactivity.this). Runonuithread (New Runnable () {@Overridepublic void Run () {//TODO auto-generated method Stub//roundprogressbar.setprogress (percent); Textview1.settext (string.valueof (percent));}}) Outputstream.flush (); if (outputstream!=null) {outputstream.close ();}} InStall ();//jimodown ();//installdown ();} catch (Clientprotocolexception e) {//TODO auto-generated catch Blocke.printstacktrace ();} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();}};}. Start ();} protected void InStall () {//TODO auto-generated method Stub//file files=new File ( Environment.getexternalstoragedirectory (), "testdemo.apk"); String path =environment.getexternalstoragedirectory (). GetPath () + "/ybds.apk"; int i=packageutils.installsilent (  This, path), if (i!=1) {File File = new file (path);   if (!file.exists ()) {return;  }intent Intent = new Intent ();  Intent.setaction ("Android.intent.action.VIEW");  Intent.addcategory ("Android.intent.category.DEFAULT");  Intent.setflags (Intent.flag_activity_new_task);  Intent.setdataandtype (uri.fromfile (file), "application/vnd.android.package-archive"); StartActivity (intent);}}}


About Android root over phone silent installation and uninstallation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.