运行我的应用程序时出现此错误。我还将surfaceflinger的权限包含在manifest.xml中

"uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER"

但在logcat中它仍然给出了相同的错误" can't access the SurfaceFlinger"
基本上我想在开发工具中运行开发设置代码。
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    try {
        Class partypes[] = new Class[1];
        partypes[0] = String.class;
        Method getService= ServiceManager.getMethod("getService", partypes );
        Object arglist[] = new Object[1];
        arglist[0] = "SurfaceFlinger";
        IBinder flinger= (IBinder)getService.invoke(smObject, arglist );

  //    IBinder flinger = ServiceManager.getService("SurfaceFlinger");
        if (flinger != null) {
            Parcel data = Parcel.obtain();
            data.writeInterfaceToken("android.ui.ISurfaceComposer");
            data.writeInt(isChecked ? 1 : 0);
            flinger.transact(mCode, data, null, 0);
            data.recycle();

            updateFlingerOptions();
        }
    } catch (RemoteException ex) {
    }
**catch (SecurityException e) {
        // TODO Auto-generated catch block
        String err=e.toString();
        Toast.makeText(DevelopmentSetting.this, err, Toast.LENGTH_SHORT).show();
    }**

    catch (NoSuchMethodException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
}

在catch securityexception中,它给出了错误java.lang.securityexception,但logcat说权限被拒绝:无法访问surfaceflinger。
manifest.xml在这里
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.nustian.android"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />
    <uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER"/>

    <uses-permission android:name="android.permission.SET_WALLPAPER"   />
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >

        <activity
            android:name=".DevelopmentSetting"
            android:label="@string/app_name" >

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>

有人帮帮我。

最佳答案

作为解决方法,将此添加到清单文件中。uid media能够使用surface flinger api,因此与它共享uid也将允许您的应用程序使用它。

  coreApp="true"
  android:sharedUserId="android.uid.media"

09-11 17:18