Can't listen to android OS intents. ex.RECEIVE_BOOT_COMPLETED
Solved
Mobile and Embedded
-
I have an android service that runs when i open my app, now I want my android service to run at boot time.
I added these permissions to the manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <uses-permission android:name="android.permission.RECEIVE_HEADSET_PLUG"/>
Here's my receiver in the manifest:
<receiver android:name="org.qtproject.example.MyBroadcastReceiver"> <intent-filter> <action android:name="android.intent.action.RECEIVE_BOOT_COMPLETED"/> <action android:name="android.intent.action.RECEIVE_HEADSET_PLUG"/> </intent-filter> </receiver>
And here's MyBroadcastReceiver.java:
import android.os.Bundle; import org.qtproject.qt5.android.bindings.QtActivity; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class MyBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent startServiceIntent = new Intent(context, org.qtproject.example.MyCustomAppService.class); context.startService(startServiceIntent); } }
-
@jsulm The service does not start. No errors or anything. I can't see it running on my android phone neither after booting or after plugging a headset.
However, if I start it from my application, it starts and i can see it running in the services on my phone. -
ok , I was able to solve the problem!
Here's the solution:
https://stackoverflow.com/a/44353506/8086424