1. Making a program a system program
We must configure Android:shareduserid= "Android.uid.system" in Manifest
<manifest xmlns:android= "http://schemas.android.com/apk/res/android" package= "Com.flyaudio.floatwindows" android:versioncode= "1" android:shareduserid= "Android.uid.system" android:versionname= "1.0" >
Plus permissions: <uses-permission android:name= "Android.permission.INJECT_EVENTS"/>
This permission is to allow a program to intercept user events such as keystrokes, touches, trackball, etc. until a time stream.
2. Simulate home, back, menu
private void Homepress () {Intent mhomeintent = new Intent (intent.action_main); Mhomeintent.addcategory (intent.category_home); Mhomeintent.addflags (Intent.flag_activity_new_task | intent.flag_activity_reset_task_if_needed); GetContext (). StartActivity (mhomeintent);} private void Backpress () { Runtime runtime = Runtime.getruntime (); try {runtime.exec ("input keyevent" + keyevent.keycode_back);} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();}} private void Menupress () { Runtime runtime = Runtime.getruntime (); try {runtime.exec ("input keyevent" + Keyevent.keycode_menu);} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();}}
In fact, there is another way:
New Thread () {public void run () { try{ Instrumentation inst = new Instrumentation (); Inst.sendkeydownupsync (Keyevent.keycode_back); } catch (Exception e) { log.e ("Exception when Onback", e.tostring ());}}} . Start ();
Inst.sendkeydownupsync (Keyevent.keycode_back);
You can pass in any key value here.
3. Add a System signature
After completing the 2 steps above, the installer discovers that a failure [install_failed_shared_user_incompatible] error occurred. Because the compiled program with Eclipse does not have a platform signature, it cannot be installed as a system program.
So you need to sign the APK.
Put the signature tool (Signapk.jar), the signing certificate (PLATFORM.PK8 and PLATFORM.X509.PEM), and the compiled apk file into the same directory
Terminal enters the directory to perform Java-jar signapk.jar-w Platform.x509.pem platform.pk8 xxx.apk out/xxx.apk
Take out the APK that was signed in the Out directory and install it
4. Attach the Signature tool
There are 2 kinds of signatures, GKFX and platform.
Download the Signature tool
Turn the program into a system app for home, back, menu and other key simulation