Introductory article: 11. Log system and permission system in Android

Source: Internet
Author: User

First, the log system in Android

Two logs commonly used in 1.java

System.out.println ();//Normal log

System.err.println ();//Warning log

Types of logs commonly used in 2.android

LOG.E (TAG, "error message");

LOG.W (Tag, "warning message");

LOG.I (Tag, "General Information");

LOG.D (Tag, "debug Information");

LOG.V (Tag, "useless Information");

PS: This log.v magical place is that it does not use, it is the meaning of existence for developers to entertain themselves, oh hehe ...

Second, the authorization system in Android

1.android Common usage rights

In the development process, sometimes we need to apply to access the user's network, contacts, cameras, front camera, handset and so on devices or power, you need to apply for these components of the permissions for the user to choose, the user can choose to give the app these permissions, you can also deny these permissions.

Add permissions: Add <uses-permission android:name= "" to the Androidmanifest.xml file/>

2. Permission Checking for code

In addition to the system-defined permissions, developers can customize the permissions themselves, such as the need to get custom permissions when executing certain code.

How to use:

Create a new class Hello.java

 Public classhello{ Public Static FinalString Permission_say_hello = "Com.example.demo.permission.sayHello";  Public Static voidSayHello (Context context) {intCheckresult =context.checkcallingorselfpermission (Permission_say_hello); if(checkresult!=packagemanager.permission_granted) {              Throw NewSecurityException ("Perform ... Need...... The Permissions "); } log.i ("Info", "Hello Android"); }}

The Permission_say_hello constant permissions defined above need to be declared in the Androidmanifest.xml file

<android:name= "Com.example.demo.permission.sayHello"/>

If you want to see the output Hello Android, you need to add permissions in the Androidmanifest.xml file

<android:name= "Com.example.demo.permission.sayHello"/>

3. Add permissions for the base component

Create a Activity,myaty

Declaring a permission in the Androidmanifest.xml file

<android:name= "Com.example.demo.permission.MyAty"/>

Add a permission property to the Myaty tag

android:permission= "Com.example.demo.permission.MyAty"

It is important to note that this permission is not required for components such as in-app startup activity, and only required when cross-app startup.

At the same time, not just the activity, the other three basic components can also add permissions. The Add method is similar.

At this point, the notes for Android entry are all over. The following time begins to summarize the knowledge of the Android interface article. Come on!

Introductory article: 11. Log system and permission system in Android

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.