Android Development, APK file installed to \system\app solution only for Root machine

Source: Internet
Author: User

In  Android , if you want to use System-restricted permissions (such as  android.permission.write_secure_settings), we need to install the program to  /system/ Under the app/ . The following is an example of  SecureSetting.apk , which demonstrates this operation. Need to prepare a mobile phone with  Root  access. 1. Connect mobile phones and computers via  USB . 2, use  adb  control mobile phone. SOURCE print?    1. $ adb push SecureSetting.apk /sdcard/  //  Upload the files you want to install and prepare for installation.      2. $ adb shell     3. $ su  //  Switch to  root  users. If you do not get  Root  permissions, this step will not succeed.      4. # mount -o remount,rw -t yaffs2 /dev/block /mtdblock3 /system //  let the partition be writable.      5. # cat /sdcard/securesetting.apk > /system/app/ securesetting.apk //  This step can be implemented with  cp , but the command is not included in the general device. If you use  mv  error:failed on  '/sdcard/network.apk '  - cross-device link will appear.       6. # mount -o remount,ro -t yaffs2 /dev/block/mtdblock3 / system //  Restore partition Properties, read-only.      7. # exit     8. $ exit   $ adb push securesetting.apk /sdcard/  //  upload the files to be installed and prepare for installation. $ adb shell$ su //  switch to  root  user. If you do not get  Root  permissions, this step will not succeed. # mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system //  Let the partition be writable. # cat /sdcard/securesetting.apk > /system/app/securesetting.apk //  This step can be used  cp  is implemented, but the command is not included in the general device. If you use  mv  error:failed on  '/sdcard/network.apk '  - cross-device link will appear.  # mount -o remount,ro -t yaffs2 /dev/block/mtdblock3 /system //   Restore partition properties, read-only. # exit$ exit restart, you can see that the  SecureSetting  has been installed.


Add, if you want to implement your own apk installed directly into the/system/app/, you need to write a installer.apk, inside the shell will be the main apk through the cat to write/system/app, and then use chmod Modify permissions, And then execute reboot on the line.
Attach the Java Execution Shell code:
public final class rootcmd {//  executes the Linux command and outputs the result protected static string  Execrootcmd (string paramstring)  {String result =  "result : "; try { Process localprocess = runtime.getruntime (). EXEC ("su ");//  The root-processed Android system has the SU Command Outputstream localoutputstream = localprocess.getoutputstream ();D Ataoutputstream localdataoutputstream = new dataoutputstream (LocalOutputStream); Nputstream localinputstream = localprocess.getinputstream ();D atainputstream  Localdatainputstream = new datainputstream (Localinputstream); String str1 = string.valueof (paramstring); string str2 = str1 +  "\ n"; localdataoutputstream.writebytes (STR2); Localdataoutputstream.flush (); string str3 = null;//while  ((Str3 = localdatainputstream.readline ())  !=  null)  {//log.d ("Result",   str3);//}localdataoutputstream.writebytes ("exit\n"); Localdataoutputstream.flush (); Localprocess.waitfor (); Return result;}  catch  (exception localexception)  {localexception.printstacktrace (); return result;}}   executes the Linux command but does not pay attention to the result output protected static int execrootcmdsilent (string paramstring)  { Try {process localprocess = runtime.getruntime (). EXEC ("su"); object localobject =  localprocess.getoutputstream ();D ataoutputstream localdataoutputstream = new  DataOutputStream ((OutputStream)  localobject); String str = string.valueof (paramstring);localobject = str +  "\ n"; Localdataoutputstream.writebytes (String)  localobject); Localdataoutputstream.flush (); Localdataoutputstream.writebytes ("exit\n"); Localdataoutputstream.flush (); Localprocess.waitfor ();int  Result = localprocess.exitvalue ();return  (Integer)  result;}  catch  (exception localexception)  {localexception.printstacktrace (); return -1;}}   Determine if Android is root, that is, whether to get root privileges protected static boolean haveroot ()  {int i  = execrootcmdsilent ("Echo test"); //  detects if  (i != -1)  {by executing a test command Return true;} Return false;}}

Android Development, APK file installed to \system\app solution only for Root machine

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.