Android自定义权限

1、在被调用程序Called的AndroidManifest.xml文件中作如下定义:

<!-- Service Permission -->
  <permission
    android:name="com.uperone.permission.SERVICE"
    android:label="@string/app_name"
    android:permissionGroup="@string/app_name"
    android:protectionLevel="normal" >
  </permission>

关于各标签属性的意义自行脑补,都是见名知意。

<service
  android:name="com.uperone.called.service.CalledService"
  android:permission="com.uperone.permission.SERVICE">
  <intent-filter>
      <action android:name="com.uperone.action.SERVICE" />
      <category android:name="android.intent.category.DEFAULT"/>
  </intent-filter>
        </service>

2、 在需要调用该组件的应用程序Call工程的AndroidManifest.mxl文件中声明对应的权限:

<uses-permission android:name="com.uperone.permission.SERVICE" />

3、在需要调用该组件的应用程序Call工程中启动、停止改服务:

case R.id.startServiceBtnId:{
      Intent intent = new Intent( "com.uperone.action.SERVICE" );
      startService(intent);
    }
    break;
原文地址:https://www.cnblogs.com/yuanting/p/4775663.html