Turn the program into a system app for home, back, menu and other key simulation

Source: Internet
Author: User

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

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.