I am trying to send a broadcast from a service but it is not received in the receiver. Following is my code
Bluetooth Service
public class BluetoothService extends Service {
public final static String TAG = "com.example.linvor.BluetoothService";
Intent intent1 = new Intent(TAG);
static boolean isRunning = false;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(final Intent intent, int flags, int startId) {
android.os.Debug.waitForDebugger();
super.onStartCommand(intent, flags, startId);
//android.os.Debug.waitForDebugger();
sendBroadcast(intent1);
return START_NOT_STICKY;
}
}
My Broadcast receiver is as follows.
ServiceBroadCastReceiver
public class ServiceBroadCastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
MainActivity.myLabel.setText("BroadCAst received");
if(intent.getAction().equals(BluetoothService.TAG)) {
Log.i("Broadcast status","BroadCast received");
}
}
}
and my manifest declaration seems like this.
manifest
<receiver
android:name=".ServiceBroadCastReceiver"
android:label="@string/app_name"
android:exported="true">
<intent-filter>
<action android:name="com.example.linvor.BluetoothService"></action>
</intent-filter>
</receiver>
One more thing:
when my service is running and sends broadcast to my activity(which is not received), my app shows app not responding.