How to obtain system permissions for Android apk

Source: Internet
Author: User

How to obtain system permissions for Android apk

In Android systems, permission levels are classified

["Normal" | "dangerous" | "signature" | "signatureOrSystem"]

Normal and dangerous can be obtained after the apk is declared in Mainifest.

Signature must have a system-level signature before it can be obtained.

SignatureOrSystem has a system-level signature or has system permissions.

Take SET_PREFERRED_APPLICATIONS as an example.

Use signapk to sign the APK

AddPreferredActivity requires permission for android. permission. SET_PREFERRED_APPLICATIONS (permission level: [signature ])

To use this permission, you need to sign the signapk. The required tool

Source code package

1) .. \ out \ host \ linux-x86 \ framework \ signapk. jar

2) .. \ build \ target \ product \ security \ platform. pk8

3) .. \ build \ target \ product \ security \ platform. x509.pk8

Put the above three files and the APK to be signed in the same directory

Cmd-> java-jar signapk. jarplatform. x509.pem platform. pk8 LauncherDemo.apk Launcher_sign.apk

This permission is used to compile an application that requires system permissions.

After installation, you can use the common install method to install the application and use zipalign to optimize the APK.

Zipalign directory android-sdk \ tools \ zipalign.exe

L optimize alignment APK

Cmd-> zipalign-v 4 old.apk new.apk

L verify alignment

Cmd-> zipalign-c-v 4 new.apk

Verification succesful indicates that the alignment is optimized successfully.

Source code compilation APK sharing system UID

This method does not require the permission SET_PREFERRED_APPLICATIONS.

1) add it to the Mainfest File

Android: sharedUserId = "android. uid. system"

2) Add the Android. mk File

LOCAL_CERTIFICATE: = platform

After compilation, use push to install the application.

Android. mk:

#Copyright 2007-2008 The Android Open Source ProjectLOCAL_PATH:=$(call my-dir)include$(CLEAR_VARS)LOCAL_SRC_FILES:= $(call all-java-files-under, src)LOCAL_PACKAGE_NAME:= LauncherDemoLOCAL_CERTIFICATE:= platforminclude$(BUILD_PACKAGE)# Use thefolloing include to make our test apk.include$(call all-makefiles-under,$(LOCAL_PATH))


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.