简体   繁体   中英

Checking for permission at runtime is failing even though I have said permission defined in the manifest

I have defined the following permission in my the manifest of RecSched application/project:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.recschedapk"
    android:versionCode="1"
    android:versionName="1.0" >
    <permission android:name="com.example.recschedapk.permission.DEADLY_ACT"
        android:label="DeadlyActivity"
        android:description="@string/permdesc"
        android:permissionGroup="android.permission-group.COST_MONEY"
        android:protectionLevel="dangerous" />
        :
        :
</manifest>

I have specified this permission in the other application(project) of WebApp:

<uses-permissiom android:name="com.example.recschedapk.permission.DEADLY_ACT" />

In the WebApp.java file I have the following function defined to check for permission at runtime:

private boolean checkPermission()
    {

        String permission = "com.example.recschedapk.permission.DEADLY_ACT";
        int res = getBaseContext().checkCallingOrSelfPermission(permission);
        Log.d("PERMCHECK", "int val : "+ res);
        return (res == PackageManager.PERMISSION_GRANTED);            
    }

The call for the above function :

               if((this.checkPermission())
        return new VideoBroadCastObject(this);

The call seems to be failing no matter what. New to android here. Can anybody tell me what the problem here is??

Thanks!

if you are not currently processing an IPC, this function will always fail.

The other app does not owns/declares this permission, that leaves the only condition that the code that is executing checkPermission() must belong to a process/pid which has been granted this permission. That means checkPermission() must be executed from an IPC call. That is, an IBinder you received from the other process calls this.

I have no idea what your process flow is but you can try this...

private boolean checkPermission() {
    String permission = "com.example.recschedapk.permission.DEADLY_ACT";
    int res = getBaseContext().checkPermission(permission, Binder.getCallingPid(), Binder.getCallingUid());
    Log.d("PERMCHECK", "int val : "+ res);
    return (res == PackageManager.PERMISSION_GRANTED);            
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM