Android自定义权限的应用

来源:互联网 发布:战国六国灭亡顺序知乎 编辑:程序博客网 时间:2024/05/16 08:40

如何自定义一个 权限呢

   <!--声明自定义权限-->    <permission android:name="com.text" />    <!--使用自定义权限-->    <uses-permission android:name="com.text" />

自定义权限的应用场景


一个app启动时,通过发送一个广播,唤醒其他app。如何 进一步区别 接受着呢?通过自定义权限。

 public void click(View v) {        Intent in = new Intent("com.text.demo1.MyReceiver");        //sendBroadcast(in);        //指定 接受权限的 广播,接收者必须 拥有该权限否则无法接受        String reqPerm = "com.text";        sendBroadcast(in, reqPerm);    }

如下 是一个广播接收者

<!--声明自定义权限-->    <permission android:name="com.text" />    <!--使用自定义权限-->    <uses-permission android:name="com.text" />    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:supportsRtl="true"        android:theme="@style/AppTheme">        <activity android:name=".MainActivity">            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>        <receiver            android:name=".MyReceiver"            android:enabled="true"            android:exported="true">            <intent-filter>                <action android:name="com.text.demo1.MyReceiver"></action>            </intent-filter>        </receiver>    </application>


0 0
原创粉丝点击