1. Are you ready for the Galaxy S20? Here is everything we know so far!

Run Application in background

Discussion in 'Android Development' started by Ganesh, Jan 6, 2010.

  1. Ganesh

    Ganesh Newbie
    Thread Starter

    Hello Friends,

    I want to develope a project in which if SIM card is changed, then messages should be sent from new SIM card to a predefined number. User should not know that the SMS are being send from his mobile. So the application needs to run in back ground. How can I achieve this?

    Thank you in regards

  2. eclipsed4utoo

    eclipsed4utoo Android Enthusiast

    I'm sorry, but this sounds like a horrible application. You want to send a SMS message from a user's phone to a number, but you don't want the user to know about it? That sounds really sneaky.
  3. 28064212

    28064212 Well-Known Member

    In fairness, it sounds more like a security app e.g. if the phone is ever stolen. I assume he means that the new user can't know anything about it, but it will be clear to the person who installed the app, and they will be the one's who set up what number the message is sent to
  4. eclipsed4utoo

    eclipsed4utoo Android Enthusiast

    that's the big "if". is the number hardcoded? or configurable by the installing user?
  5. Ganesh

    Ganesh Newbie
    Thread Starter

    Hello Friends,

    I want to develope the security application in which The installer of application will set any number as reporting number. Then if the phone is stolen and used with another SIM card then the application should send SMS from this new SIM (without informing the new User [Thief]). So this application should run in back ground. Sorry to post confusing discription of my application in my first query.

    Thank you in advance
  6. Ganesh

    Ganesh Newbie
    Thread Starter

    Hello Friends,

    I tried with the use of Service. but it does not worked. I checked logcat (thanks to ecliped4utoo; he taught me how to check logcat) but I found that my application is not going inside the Service class

    My Activity class is as follows

    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.view.animation.Animation;
    import android.view.animation.AnimationUtils;
    import android.widget.Button;
    import android.widget.LinearLayout;
    public class MSMAndroid extends Activity {
    private static final String TAG = "MSMAndroid";
    /** Called when the activity is first created. */
    Button btn_StartMSM;
    LinearLayout layout;
    LinearLayout layMain;


    public void onCreate(Bundle savedInstanceState) {
    btn_StartMSM =new Button(this);
    layout = new LinearLayout(this);
    layMain= new LinearLayout(this);

    btn_StartMSM.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {

    Intent int1 = new Intent( );
    startService(int1 );

    //Intent int = new Intent( this, MyService.class );
    //startService(int );
    //Intent a1 =new Intent(MSMAndroid.this,MSMService.class);
    //Animation anim = AnimationUtils.loadAnimation(MSMAndroid.this, 1);
    public void startService ()
    Intent serviceIntent = new Intent(this, MSMService.class);
    Log.d(TAG, "Start service");
    btn_StartMSM.setText("After Start");


    My service class is

    package com.MSMAndroid;
    import android.app.PendingIntent;
    import android.app.Service;
    import android.content.Intent;
    import android.os.IBinder;
    import android.telephony.gsm.SmsManager;
    import android.widget.LinearLayout;
    public class MSMService extends Service{
    MSMAndroid msmAndroid;
    SmsManager smsManager;
    PendingIntent i1;
    LinearLayout layout2;
    String destAddr = "919860650337", mMessageText =
    "Welcome to MSMAndroid";
    public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
    public void onCreate() {
    // TODO Auto-generated method stub
    msmAndroid = new MSMAndroid();
    smsManager =SmsManager.getDefault();
    layout2 = new LinearLayout(this);
    i1 = PendingIntent.getBroadcast(this, 0, new Intent(), 0);
    smsManager.sendTextMessage(destAddr, null, mMessageText, i1, null);

    public void onStart(final Intent intent, final int startId) {
    super.onStart(intent, startId);



    My AndroidMenifest is

















    My R.java is as follows

    * This class was automatically generated by the
    * aapt tool from the resource data it found. It
    * should not be modified by hand.
    package com.MSMAndroid;
    public final class R {
    public static final class attr {
    public static final class drawable {
    public static final int icon=0x7f020000;
    public static final class layout {
    public static final int main=0x7f030000;
    public static final class string {
    public static final int app_name=0x7f040001;
    public static final int hello=0x7f040000;

    I am not getting where I am commiting the mistake

    Thank you in advance
  7. eclipsed4utoo

    eclipsed4utoo Android Enthusiast

    use the code tags. it properly formats the text so it's easier to read.

    you can use them like this....

    [ code]


    remove the space before the first "code", and you will get this...

    Code (Text):
    2. // just copied your code
    3. public void onCreate(Bundle savedInstanceState) {
    4.       super.onCreate(savedInstanceState);
    5.       btn_StartMSM =new Button(this);
    6.       btn_StartMSM.setText("Button");
    7.       layout = new LinearLayout(this);
    8.       layMain= new LinearLayout(this);
    9.       layout.addView(btn_StartMSM);
    10.       setContentView(layout);
    11. }

Share This Page