• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Run Application in background

Ganesh

Newbie
Dec 25, 2009
18
0
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
 
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.
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
 
Upvote 0
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

that's the big "if". is the number hardcoded? or configurable by the installing user?
 
Upvote 0
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
 
Upvote 0
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;

@Override

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
btn_StartMSM =new Button(this);
btn_StartMSM.setText("Button");
layout = new LinearLayout(this);
layMain= new LinearLayout(this);
layout.addView(btn_StartMSM);
setContentView(layout);


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);
//startService(a1);
//Animation anim = AnimationUtils.loadAnimation(MSMAndroid.this, 1);
//MSMAndroid.this.layMain.startAnimation(anim);
//startService();
}
});
}
public void startService ()
{
Intent serviceIntent = new Intent(this, MSMService.class);
Log.d(TAG, "Start service");
startService(serviceIntent);
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";
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
msmAndroid = new MSMAndroid();
smsManager =SmsManager.getDefault();
layout2 = new LinearLayout(this);
i1 = PendingIntent.getBroadcast(this, 0, new Intent(), 0);
//destAddr=""+phonenumber.getText();
smsManager.sendTextMessage(destAddr, null, mMessageText, i1, null);
msmAndroid.btn_StartMSM.setText("HERE");
msmAndroid.setContentView(msmAndroid.layout);
//msmAndroid.setContentView(layout2);
//setForeground(true);



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

}


}


My AndroidMenifest is


<?​
xmlversion="1.0"encoding="utf-8"?>
<
manifestxmlns:android="http://schemas.android.com/apk/res/android"

package="com.MSMAndroid"

android:versionCode="1"

android:versionName="1.0">

<applicationandroid:icon="@drawable/icon"android:label="@string/app_name"android:debuggable="true">

<activityandroid:name=".MSMAndroid"

android:label="@string/app_name">

<serviceandroid:name=".MSMService"/>

<intent-filter>

<actionandroid:name="android.intent.action.MAIN"/>

<categoryandroid:name="android.intent.category.LAUNCHER"/>

</intent-filter>

</activity>


</application>

<uses-sdkandroid:minSdkVersion="2"/>
<
uses-permissionandroid:name="android.permission.SEND_SMS"></uses-permission>

</
manifest>

My R.java is as follows


/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* 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
 
Upvote 0
use the code tags. it properly formats the text so it's easier to read.

you can use them like this....

[ code]

[/code]

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

Code:
// just copied your code
public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      btn_StartMSM =new Button(this);
      btn_StartMSM.setText("Button");
      layout = new LinearLayout(this);
      layMain= new LinearLayout(this); 
      layout.addView(btn_StartMSM);
      setContentView(layout);
}
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones