How to fix “IntentReceiver components are not allowed to bind to services”

I can't find the source of this error ( "IntentReceiver components are not allowed to bind to services") I see in my logcat. Sorry, I've pasted much of the logcat but the main error is in bold.

Note that the first reference to my code in the logcat error listing is an AsyncTask that is itself called from an IntentService that is called from a BroadcastReceiver.

04-17 07:46:03.163: W/dalvikvm(23525): threadid=24: thread exiting with uncaught exception (group=0x417582a0) 04-17 07:46:03.173: D/AccountsActivity(23525): onRequestDone 04-17 07:46:03.178: E/AndroidRuntime(23525): FATAL EXCEPTION: AsyncTask #2 04-17 07:46:03.178: E/AndroidRuntime(23525): java.lang.RuntimeException: An error occured while executing 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): Caused by: android.content.ReceiverCallNotAllowedException: IntentReceiver components are not allowed to bind to services 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(Unknown Source) 04-17 07:46:03.178: E/AndroidRuntime(23525): at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source) 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: thread exiting with uncaught exception (group=0x417582a0) 04-17 07:46:03.173: D/AccountsActivity(23525): onRequestDone 04-17 07:46:03.178: E/AndroidRuntime(23525): FATAL EXCEPTION: AsyncTask #2 04-17 07:46:03.178: E/AndroidRuntime(23525): java.lang.RuntimeException: An error occured while executing 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): Caused by: android.content.ReceiverCallNotAllowedException: IntentReceiver components are not allowed to bind to services 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(Unknown Source) 04-17 07:46:03.178: E/AndroidRuntime(23525): at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source) 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

The reference to "doInBackground" in the logcat is the only reference to my (not Android OS) code, and is only a Google Cloud Endpoint call:

uEndpoint.doRegistration(registrationId).execute();

No broadcast receiver I've defined has any explicit "bindService" call in it.

Where could I be illegally binding to a service? Any ideas on where to look to trace down this problem?

Thanks.

Answers


The problem comes from incorrect usage of GoogleAccountCredential in an IntentService. The IntentService gets its Context object from the BroadcastReceiver that started it. This BroadcastReceiver has a "ReceiverRestrictedContext". Using this restricted context in

GoogleAccountCredential.usingAudience(context,.,.)  //-- this context was a "ReceiverRestrictedContext" 

doesn't throw an exception until the credential gets used in an endpoint execution.

I fixed it by using

GoogleAccountCredential.usingAudience(getApplicationContext(),.,.)

in the IntentService.


Need Your Help

Multipart/form-data example in slim micro framework

php slim

I have been developing apis for android and ios app in slim framework. Recently i came across a problem where i need to upload videos or images using multipart/form-data.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.