bindservice期间的异常

时间:2012-11-23 11:17:32

标签: android android-intent android-service

当我尝试从我的应用程序执行bindService时出现以下错误。我正在使用Android源代码,我确信我尝试绑定的这个服务不是从其他地方开始的。我通过设置确认了这一点 - >应用程序 - >运行,显示正在运行的服务。

01-02 00:06:54.531: INFO/PowerManagerService(425): Start Light.setBrightness(), [20],  [3]
01-02 00:06:56.473: INFO/PowerManagerService(425): Start Light.setBrightness(), [130], [3]
01-02 00:06:58.055: WARN/dalvikvm(4956): threadid=1: thread exiting with uncaught exception (group=0x40b70390)
01-02 00:06:58.055: WARN/ActivityManager(425): Permission Denial: Accessing service ComponentInfo{jp.co.abc.android.omrsettings/jp.co.xyz.bluetooth.profile.TIPServer} from   pid=4956, uid=10158 requires jp.co.abc.android.OMRSettings.permission.Access
01-02 00:06:58.065: ERROR/AndroidRuntime(4956): FATAL EXCEPTION: main
java.lang.SecurityException: Not allowed to bind to service Intent {      act=jp.co.xyz.bluetooth.api.ITimeServer }
at android.app.ContextImpl.bindService(ContextImpl.java:1187)
at android.content.ContextWrapper.bindService(ContextWrapper.java:370)
at jp.co.abc.middleware.tip.LeTimeServerProfile.startTimeServer(LeTimeServerProfile.java:45)
at jp.co.abc.tip.TimeActivity.onClick(TimeActivity.java:49)
at android.view.View.performClick(View.java:3511)
at android.view.View$PerformClick.run(View.java:14133)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4507)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
at dalvik.system.NativeStart.main(Native Method)
01-02 00:06:58.095: WARN/ActivityManager(425): Force finishing activity      jp.co.abc.tip/.TimeActivity

奇怪的是,当我从设备中删除特定的应用程序时,不会发生此错误。有人可以告诉我出现此应用程序时出现此错误的原因可能是什么原因,当我删除此应用程序时不会出现这种情况?

非常感谢任何帮助。

修改

这是我用来做bindservice的代码:

mContext.bindService(new Intent("jp.co.xyz.bluetooth.api.ITimeServer"),  time_connection, Context.BIND_AUTO_CREATE);

ServiceConnection time_connection = new ServiceConnection() {
     public void onServiceConnected(ComponentName name, IBinder service){
         mTime = ITimeServer.Stub.asInterface(service);
         try {
             mTime.startTIPServer(callback,Constants.TIME_SOURCE_CELLULAR_NETWORK,46);
         } catch (RemoteException e) {
             Log.e(TAG, " startTIPServer error "); 
         }
     }

    public void onServiceDisconnected(ComponentName name){
        mTime = null;
     }
  };

1 个答案:

答案 0 :(得分:0)

错误是权限错误。您的应用程序看起来需要拥有权限jp.co.abc.android.OMRSettings.permission.Access。将此添加到您的清单:

<uses-permission android:name="jp.co.abc.android.OMRSettings.permission.Access"/>