Android Permissions configuration and invocation

Source: Internet
Author: User

1  Packagecom.example.metrox.codepermission;2 3 ImportAndroid.content.Context;4;5 6 /**7 * Created by Metrox on 2016/6/22.8  */9  Public classHello {Ten      Public Static FinalString Permisson_say_hello = "Com.example.metrox.codepermission.permission.SAY_HELLO"; One      Public Static voidSayHello (Context context) { A         intresult =context.checkcallingorselfpermission (Permisson_say_hello); -         if(Result! =packagemanager.permission_granted) { -              Throw  NewSecurityException ("Execute SayHello method requires permission:" +Permisson_say_hello); the         } -SYSTEM.OUT.PRINTLN ("Permission test succeeded"); -     } -}
1  Packagecom.example.metrox.codepermission;2 3;4 ImportAndroid.os.Bundle;5 6  Public classMainactivityextendsappcompatactivity {7 8 @Override9     protected voidonCreate (Bundle savedinstancestate) {Ten         Super. OnCreate (savedinstancestate); One Setcontentview (r.layout.activity_main); AHello.sayhello ( This); -     } -}
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Manifestxmlns:android= "Http://"3  Package= "Com.example.metrox.codepermission">4     <PermissionAndroid:name= "Com.example.metrox.codepermission.permission.SAY_HELLO"></Permission>5     <uses-permissionAndroid:name= "Com.example.metrox.codepermission.permission.SAY_HELLO"></uses-permission>6     <Application7         Android:allowbackup= "true"8 Android:icon= "@mipmap/ic_launcher"9 Android:label= "@string/app_name"Ten Android:supportsrtl= "true" One Android:theme= "@style/apptheme"> A         <ActivityAndroid:name=". Mainactivity "> -             <Intent-filter> -                 <ActionAndroid:name= "Android.intent.action.MAIN" /> the  -                 <categoryAndroid:name= "Android.intent.category.LAUNCHER" /> -             </Intent-filter> -         </Activity> +     </Application> -  + </Manifest>

Android Permissions configuration and invocation

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: 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.