Android Note 3.12 Android Access system

Source: Internet
Author: User

Course Background:
In Android has a very good control mechanism, developers need to know how to use, ordinary users need to know how to distinguish, combined to effectively prevent the spread of the Android platform virus.

Core content:
1. Define Permissions
2. Do permission checking in the code
3. Add a permission check for the base component

Request permission Instance

Androidmanifest.xml:

<!--Android Installer can prompt the user according to this permission, the permission information required by the program--><uses-permission android:name= "Android.permission.INTERNET"/ >

Activity_main.xml:

<WebView        android:layout_width= "Match_parent"        android:layout_height= "Match_parent"         Android:id= "@+id/wv" ></WebView>

Mainactivity.java:

Private= (WebView) Findviewbyid (R.ID.WV); Wv.loadurl ("http://www.lanyunwork.com/"); // access to Web pages requires Internet access first

To add a permission check for code

Androidmanifest.xml:

<permission android:name= "Com.lanyunwork.l312_checkpermissionincode.permission.SAY_HELLO"/>< Uses-permission android:name= "Com.lanyunwork.l312_checkpermissionincode.permission.SAY_HELLO"/>

Hello.java:

 Public classHello { Public Static FinalString Permission_say_hello = "Com.lanyunwork.l312_checkpermissionincode.permission.SAY_HELLO";  Public Static voidSayHello (Context context) {intCheckresult =context.checkcallingorselfpermission (Permission_say_hello); if(Checkresult! =packagemanager.permission_granted) {            Throw NewSecurityException ("Execute SayHello method requires Com.lanyunwork.l312_checkpermissionincode.permission.SAY_HELLO permission"); } System.out.println ("Hello Jikexueyuan"); }}

Then call Hello.sayhello (this) in the mainactivity;

If you do not add permissions in Androidmanifest.xml uses-..., you will get an error

To add a permission check for a base component

The same principle is true for configuring permissions in activity.

In the same application, this permission does not work.

In other applications, to start this program, you have to add <uses-..., then the Android installer will know that the app will require XX permissions.

Android Note 3.12 Android Access system

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.