2012-04-16 83 views
1

运行我的应用程序时出现此错误。我也包含在manifest.xml中权限拒绝:无法访问SurfaceFlinger

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

为SurfaceFlinger的权限但仍给了同样的错误" can't access the SurfaceFlinger"在logcat中。

基本上我想在开发工具中运行开发设置代码。

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(); 
    } 
} 
} 

在捕获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> 

有人帮我。

+0

请发表完整的例外。 – MahdeTo 2012-04-16 06:29:18

回答

0

不要忘记添加其相对权限:

<uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER" /> 
+0

我添加了相对权限但仍然给SecurityException错误。 – user1335632 2012-04-16 10:12:03

+0

你应该总是包含错误堆栈。否则没有人可以找出什么可能是错误的... – waqaslam 2012-04-16 10:27:55

+0

粘贴您的整个AndroidManifest.xml – waqaslam 2012-04-17 10:03:53

3

解决方法是,将它添加到您的清单文件。 UID媒体能够使用表面抛掷API,因此与其共享UID将允许您的应用程序使用它。

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

工作对我来说...我的应用程序是一个系统应用程序。 – benchuk 2015-06-28 12:24:25