Hello Mark,
I tried with the use of Service. but it does not worked
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
<?
xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.MSMAndroid"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<activity android:name=".MSMAndroid"
android:label="@string/app_name">
<service android:name=".MSMService"/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="2" />
<uses-permission android: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