Answer the question
In order to leave comments, you need to log in
Android - Why doesn't the broadcast receiver fire when the device goes to sleep?
So, I am writing an application that should do some actions when the tablet is connected to the docking station.
Declared in the manifest
<receiver android:name="MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.DOCK_EVENT"/>
</intent-filter>
</receiver>
<service android:name="PowerService"></service>
public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
context.startService(new Intent(context, PowerService.class));
}
}
public int onStartCommand(Intent intent, int flags, int startId) {
IntentFilter ifilter = new IntentFilter(Intent.ACTION_DOCK_EVENT);
dockIntent = registerReceiver(null, ifilter);
Toast.makeText(this, "Старт сервиса...", Toast.LENGTH_LONG).show();
if(dockIntent != null){
//бла-бла-бла
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question