Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to register a content observer without an activity?

I need to listen all incoming and outgoing sms and store it in a text file. For this I am using broadcast listener to listen all incoming messages. This works fine. But for outgoing sms, how to register content observer without activity? I don't want any activity in my application. Now the broadcast receiver listens even after reboot, will content observer too listen even after reboot? How to merge 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, the class that extends 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.

like image 422
Vivek Avatar asked Apr 28 '11 05:04

Vivek


1 Answers

You'll need a http://developer.android.com/reference/android/app/Service.html . Create one of those, set it to run on boot and register your content observer from in there.

like image 57
Femi Avatar answered Oct 20 '22 11:10

Femi