Q:

Binding service by BroadcastReceiver

My Application uses a service that is started by a BOOT_COMPLETE BroadcastReceiver, in run i'm getting an error
my code: 
public class projet extends BroadcastReceiver { 
 public void onReceive(Context context, Intent intent) { 

  intent = new Intent(context, ScreenshotService.class);
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  context.bindService(intent, aslServiceConn, Context.BIND_AUTO_CREATE);
}
}

error:
java.lang.RuntimeException: Unable to start receiver com.example.projet: android.content.ReceiverCallNotAllowedException: BroadcastReceiver components are not allowed to bind to services

A:

One should not bind a service from Broadcast receiver.
The reason is broadcast receivers are light weight components, where it has to finish its functionality with in not more than 10 seconds maximum. Else android may forcefully kill your receiver. Binding (establishing connection to) a service may take more than 10 seconds in some worst cases, that's why android won't allow it.
Rules for Broadcast Receivers:

Broadcast receivers will not have any UI(mostly) and it will have only background logic.
Broadcast receivers will have the maximum time limit of 10 sec to finish its functionality otherwise it will crash.
You should not do long running operations or asynchronous operations in the receiver.
    Example: a. Preparing SD card.
     b. Uploading / Downloading files from internet.
             c. Creating Db files.
             d. Binding to services
Do not show dialog to the user in broadcast receiver. (this is asynchronous operation)
You can use “ toast” or “Notifications”.
Don’t write any heavy functionalities.

Ref taken from developer android

A:

If you know that the Service is running you can aquire its Binder with BroadcastReceiver.peekService(Context, Intent) method (See peekService docs).
But, as it is already said in the other answers, it is not allowed to bind a Service from within a BroadcastReceiver. 

A:

Best way is to first start an IntentService from BroadcastReceiver.onReceive() using:
context.StartService(new Intent(context, YourIntentService.class));

Then in the IntentService.onHandleIntent():
@Override
protected void onHandleIntent(Intent intent) {
    mContext = getApplicationContext();
    mContext.bindService(new Intent("com.ServiceToBind.BIND"), yourConnection, Context.BIND_AUTO_CREATE);
}

