Android run app secretly in background
<p>I have a client that needs a spy app that will run in the background - take received messages, sent messages, gps location etc. Can I start a service without user interface of Activity? As I understand, I need a service and receiver, I also need to call the receiver on let's say battery low, battery ok - some very often triggered intents. How can I test this on emulator?</p>

<p>For now this is what I have </p>

<pre><code>public class MyReceiver extends BroadcastReceiver{

@Override
public void onReceive(Context context, Intent intent) {

    if(intent.getAction() != null)
    {
        if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED) ||
            intent.getAction().equals(Intent.ACTION_USER_PRESENT))
        {
            context.startService(new Intent(context, MyService.class));
        }
    // TODO Auto-generated method stub

}
</code></pre>

<p>}
    }</p>

<p>for receiver and</p>

<pre><code>public class MyService extends Service {

@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public void onCreate() {
super.onCreate();
Toast.makeText(this,"Service created ...",Toast.LENGTH_LONG).show();


}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    // We want this service to continue running until it is explicitly
    // stopped, so return sticky.
    return START_STICKY;
}


@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service destroyed ...",
Toast.LENGTH_LONG).show();

}
</code></pre>

<p>}</p>

<p>for service .
I put this in my manifest</p>

<pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.services"
android:versionCode="1"
android:versionName="1.0" &gt;

&lt;uses-sdk
    android:minSdkVersion="4"
    android:targetSdkVersion="4" /&gt;
&lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/&gt;

&lt;application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" &gt;
    &lt;service android:name=".MyService"&gt;&lt;/service&gt;
    &lt;receiver  android:name=".MyReceiver"&gt;&lt;/receiver&gt;
&lt;/application&gt;
</code></pre>

<p></p>

<p>Am I on a good way?</p>
