Android: How to register content watcher without activity?

I need to listen to all incoming and outgoing sms and save them in a text file. To do this, I use a broadcast listener to listen to all incoming messages. It works great. But for outgoing SMS, how to register a content observer without activity? I do not want to do any activity in my application. Now the broadcast receiver is tapped even after a reboot, will the content observer be tapped even after a reboot? How to combine these two functions?

Here is part of my manifest.xml

<receiver class="map" android:name=".map" android:enabled="true"> <intent-filter> <action android:value="android.provider.Telephony.SMS_RECEIVED" android:name="android.provider.Telephony.SMS_RECEIVED" /> </intent-filter> </receiver> 

Here's the class extending the broadcast receiver

 public class map extends BroadcastReceiver { /** Called when the activity is first created. */ private static final String ACTION = "android.provider.Telephony.SMS_RECEIVED"; public void onReceive(Context context, Intent intent) { // Here I store the sms in text file } 

Any help is appreciated. Thanks.

+6
source share
1 answer

You will need http://developer.android.com/reference/android/app/Service.html . Create one of them, set it to start at boot, and register your content observer there.

+3
source

Source: https://habr.com/ru/post/886851/


All Articles