[android-developers] I found the way how to SmsReceiver invoke my Application

2009-05-22 Thread doananhtai

public class MyActivity extends Activity
{

public static MyActivity myactivity;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

myactivity = this;

// Check whether MyActivity is not launched by History (long press on
home)
// if launched by History it may be get the un-wanted parameters had
been set by SmsReceiver before
int flag = getIntent().getFlags();
flag = flag  Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY;
if (flag != Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY)
{
//Get parameter had put by SmsReceiver
Bundle bundle = getIntent().getExtras();
if (bundle != null)
{
String smsbody = (String) bundle.getString(SMS);
if (smsbody != null)
{
//Do some thing with smsbody
}
}
}
}

public class SmsReceiver extends BroadcastReceiver
{

MyActivity myactivity;

@Override
public void onReceive(Context context, Intent intent)
{
myactivity = MyActivity.myactivity;

//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = ;
if (bundle != null)
{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get(pdus);
msgs = new SmsMessage[pdus.length];
for (int i=0; imsgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus
[i]);
str += SMS from  + msgs[i].getOriginatingAddress
();
str +=  :;
str += msgs[i].getMessageBody().toString();
str += \n;
if (i == msgs.length-1)
{
address = msgs[i].getOriginatingAddress();
Msg = msgs[i].getMessageBody().toString();
}
}

//---display the new SMS message---
try
{
// if MyActivity is running either Frontground or 
Background
context.startActivity(myactivity.getIntent()); // just 
for in case
MyActivity is Background

/* Do some thing with myactivity. or 
myactivity.()  */

}
catch (Exception e) //in case myactivity had been closed
{
//Launch new myactivity with parameter SMS = str;
Intent i = new Intent(context, aContext.getClass());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra(SMS, str);
context.startActivity(i);
}
}
}
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Start Application with SMS

2009-05-21 Thread doananhtai

Try this code in SmsReceiver


// Invoke MyActivityName
Intent i = new Intent(context, MyActivityName.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);


But after start my application, I don't know how to let it process the
received sms content...hic


On May 2, 3:04 am, theMerchant ali.taciro...@gmail.com wrote:
 Hello Everyone,

 I would like to know if anybody knows how I canstartmyapplication
 with an incoming SMS message.

 For example, I send an SMS message from phone A to Phone B. When Phone
 B receives the message, it checks if it is sent to my program. If it
 is, it starts(run) myapplication. Important thing here is that my
 program is not running in the device unless SMS is received, so it can
 not be listening for SMS itself.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] How to specify both message body and Destination Number in SMS intent.

2009-05-21 Thread doananhtai

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sms:
1234567890));
intent.putExtra(sms_body, the SMS text);
startActivity(intent);

NOTE: without  Intent.setType(vnd.android-dir/mms-sms);
this will erase the destination number.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---