次のように 1 つのリモート サービスを作成しました。
<service android:name=".XYZService"
android:permission="com.xyz.service"
android:exported="true">
<intent-filter>
<action android:name="com.abc.def.XYZService"/>
</intent-filter>
</service>
次のようにクライアントアプリケーションサービスを使用して、このサービスとバインドしようとしています:- //client service onStartCommand コード:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
boolean ret;
try {
Intent i = new Intent("com.abc.def.XYZService");
ret = getApplicationContext().bindService(i, serviceConnection,
Context.BIND_AUTO_CREATE);
if (ret == false) {
//log error
}
} catch (SecurityException e) {
e.printStackTrace();
}
return super.onStartCommand(intent, flags, startId);
}
クライアント アプリケーション マニフェストには次の権限があります:-
<uses-permission android:name="com.xyz.service" />
それでも、次の例外が発生します:- セキュリティ例外: クライアント サービスには、xyz サービスにバインドする権限がありません。
ここでの私の意図は、エクスポートされたサービスを何らかの権限で保護し、クライアント アプリケーションでその権限を使用してエクスポートされたサービスにアクセスすることです。どんな助けでも大歓迎です。