Android自定义权限的应用

    xiaoxiao2021-03-25  60

    如何自定义一个 权限呢

    <!--声明自定义权限--> <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>

    转载请注明原文地址: https://ju.6miu.com/read-40345.html

    最新回复(0)