[英]Permission denial: Can't access the SurfaceFlinger
运行我的应用程序时出现此错误。 我还在manifest.xml中包含了surfaceFlinger的权限
"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媒体能够使用Surface flinger API,因此与它共享UID也将允许您的应用程序也使用它。
coreApp="true"
android:sharedUserId="android.uid.media"
您的应用需要使用平台证书签名才能访问此权限。 通常只有系统应用程序具有此功能。 更多信息在这里:
https://groups.google.com/forum/#!topic/android-porting/aN6D_vL9xxE
不要忘记添加其相对权限:
<uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.