如何修复“不允许IntentReceiver组件绑定到服务”

时间:2013-04-17 21:22:05

标签: android android-intent broadcastreceiver android-service

我无法找到此错误的来源("不允许IntentReceiver组件绑定到服务")我在我的logcat中看到。对不起,我已经粘贴了很多logcat,但主要错误是粗体

请注意,在logcat错误列表中对我的代码的第一个引用是一个AsyncTask,它本身是从一个从BroadcastReceiver调用的IntentService调用的。

  

04-17 07:46:03.163:W / dalvikvm(23525):threadid = 24:线程退出   与未捕获的异常(组= 0x417582a0)04-17 07:46:03.173:   D / AccountsActivity(23525):onRequestDone 04-17 07:46:03.178:   E / AndroidRuntime(23525):致命异常:AsyncTask#2 04-17   07:46:03.178:E / AndroidRuntime(23525):java.lang.RuntimeException:An   执行doInBackground时发生错误()04-17 07:46:03.178:   E / AndroidRuntime(23525):at   android.os.AsyncTask $ 3.done(AsyncTask.java:299)04-17 07:46:03.178:   E / AndroidRuntime(23525):at   java.util.concurrent.FutureTask中$ Sync.innerSetException(FutureTask.java:273)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   java.util.concurrent.FutureTask.setException(FutureTask.java:124)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   java.util.concurrent.FutureTask中$ Sync.innerRun(FutureTask.java:307)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   java.util.concurrent.FutureTask.run(FutureTask.java:137)04-17   07:46:03.178:E / AndroidRuntime(23525):at   android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:230)04-17   07:46:03.178:E / AndroidRuntime(23525):at   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:569)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   java.lang.Thread.run(Thread.java:856)04-17 07:46:03.178:    E / AndroidRuntime(23525):引起:   android.content.ReceiverCallNotAllowedException:IntentReceiver   组件不允许绑定到服务 04-17 07:46:03.178:   E / AndroidRuntime(23525):at   android.app.ReceiverRestrictedContext.bindService(ContextImpl.java:178)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   com.google.android.gms.auth.GoogleAuthUtil.getToken(未知来源)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   com.google.android.gms.auth.GoogleAuthUtil.getToken(未知来源)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:192)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential $ RequestHandler.intercept(GoogleAccountCredential.java:217)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   com.google.api.client.http.HttpRequest.execute(HttpRequest.java:836)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:412)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:345)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:463)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   com.my_package.ServerRequests $ 11.doInBackground(ServerRequests.java:378)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   com.my_package.ServerRequests $ 11.doInBackground(ServerRequests.java:1)   04-17 07:46:03.163:W / dalvikvm(23525):threadid = 24:线程退出   与未捕获的异常(组= 0x417582a0)04-17 07:46:03.173:   D / AccountsActivity(23525):onRequestDone 04-17 07:46:03.178:   E / AndroidRuntime(23525):致命异常:AsyncTask#2 04-17   07:46:03.178:E / AndroidRuntime(23525):java.lang.RuntimeException:An   执行doInBackground时发生错误()04-17 07:46:03.178:   E / AndroidRuntime(23525):at   android.os.AsyncTask $ 3.done(AsyncTask.java:299)04-17 07:46:03.178:   E / AndroidRuntime(23525):at   java.util.concurrent.FutureTask中$ Sync.innerSetException(FutureTask.java:273)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   java.util.concurrent.FutureTask.setException(FutureTask.java:124)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   java.util.concurrent.FutureTask中$ Sync.innerRun(FutureTask.java:307)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   java.util.concurrent.FutureTask.run(FutureTask.java:137)04-17   07:46:03.178:E / AndroidRuntime(23525):at   android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:230)04-17   07:46:03.178:E / AndroidRuntime(23525):at   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:569)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   java.lang.Thread.run(Thread.java:856)04-17 07:46:03.178:   E / AndroidRuntime(23525):引起:   android.content.ReceiverCallNotAllowedException:IntentReceiver   组件不允许绑定到服务04-17 07:46:03.178:   E / AndroidRuntime(23525):at   android.app.ReceiverRestrictedContext.bindService(ContextImpl.java:178)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   com.google.android.gms.auth.GoogleAuthUtil.getToken(未知来源)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   com.google.android.gms.auth.GoogleAuthUtil.getToken(未知来源)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:192)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential $ RequestHandler.intercept(GoogleAccountCredential.java:217)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   com.google.api.client.http.HttpRequest.execute(HttpRequest.java:836)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:412)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:345)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:463)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   com.my_package.ServerRequests $ 11.doInBackground(ServerRequests.java:378)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   com.my_package.ServerRequests $ 11.doInBackground(ServerRequests.java:1)   04-17 07:46:03.178:E / AndroidRuntime(23525):at   android.os.AsyncTask $ 2.call(AsyncTask.java:287)04-17 07:46:03.178:   E / AndroidRuntime(23525):at   java.util.concurrent.FutureTask中$ Sync.innerRun(FutureTask.java:305)   04-17 07:46:03.178:E / AndroidRuntime(23525):... 5 more

对" doInBackground"的引用在logcat中是对我(不是Android OS)代码的唯一引用,并且只是一个Google Cloud Endpoint调用:

uEndpoint.doRegistration(registrationId).execute();

我定义的广播接收器没有任何明确的" bindService"打电话给它。

我在哪里可以非法绑定服务?关于在哪里寻找追查这个问题的任何想法?

感谢。

1 个答案:

答案 0 :(得分:2)

问题来自IntentService中GoogleAccountCredential的错误使用。 IntentService从启动它的BroadcastReceiver获取其Context对象。该BroadcastReceiver具有“ReceiverRestrictedContext”。

中使用此受限制的上下文
GoogleAccountCredential.usingAudience(context,.,.)  //-- this context was a "ReceiverRestrictedContext" 
在端点执行中使用凭证之前,

不会抛出异常。

我使用

修复了它
GoogleAccountCredential.usingAudience(getApplicationContext(),.,.)

在IntentService中。