Java 如何在 Android 中对 Activity 强制执行自定义权限?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21693480/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 10:06:16  来源:igfitidea点击:

How to enforce the custom permission on an Activity in Android?

javaandroidandroid-activitypermissions

提问by Master

I have created a custom permission in android as:

我在 android 中创建了一个自定义权限:

<permission
    android:name="com.master.me.CUSTOM_PERMISSION_TEST"
    android:description="@string/des_permission"
    android:label="labelhere">
</permission>

How will I enforce this in my Activity in AndroidManifest.xmlfile?

我将如何在我的活动AndroidManifest.xml文件中强制执行此操作?

采纳答案by Pankaj Kumar

Use android:permissionattribute into activity tag.

android:permission在活动标签中使用属性。

Like below

像下面

<activity android:permission="com.master.me.CUSTOM_PERMISSION_TEST"
            android:name=".YourActivity"
            android:label="@string/activity_label" />

And you need to add uses-permissionto your custom permission, when your other application needs to launch this activity.

uses-permission当您的其他应用程序需要启动此活动时,您需要添加到您的自定义权限。

<uses-permission android:name="com.master.me.CUSTOM_PERMISSION_TEST"/>


An In-Depth Introduction to the Android Permission Modelis a very good article to understand permission in Android. And How to use custom permissions in Android?is also a very good SO thread.

An In-Depth Introduction to the Android Permission Model是一篇很好的文章,可以理解Android中的权限。以及如何在 Android 中使用自定义权限?也是一个非常好的SO线程。