Hi All,
First of all i must say that i am very new to android.
I am trying to develop an application which will receive an SMS alert
and notofy the user with some sound. I have written the main
SMSReceiver class as follows;
package com.android.sms;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsMessage;
public class SMSReceiver extends BroadcastReceiver {
/* package */ static final String ACTION =
"android.provider.Telephony.SMS_RECEIVED";
public void onReceive(Context context, Intent intent)
{
if (intent.getAction().equals(ACTION))
{
String buf = new String();
Bundle bundle = intent.getExtras();
if (bundle != null)
{
Object[] pdusObj = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdusObj.length];
int length = pdusObj.length;
for (int i = 0; i<length; i++)
{
messages[i] = SmsMessage.createFromPdu
((byte[]) pdusObj[i]);
buf = messages[0].getMessageBody();
//buf = messages[0].toString();
if (null != buf)
{
Intent startActivity = new Intent();
startActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity.setAction("com.myexample.START_THE_MUSIC");
context.startActivity(startActivity);
}
}
}
}
}
}
However, I am not able to listen to the music when I try to send a SMS
through DDMS.
I have written the com.myexample.START_THE_MUSIC as follows:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
public class SMSAlert extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = getIntent();
String action = i.getAction();
if (action != null &&
action.equals("com.myexample.START_THE_MUSIC"))
{
//setContentView(R.layout.main);
startService(new Intent
("com.myexample.START_AUDIO_SERVICE"));
}
else
{
finish();
}
}
And the com.myexample.START_AUDIO_SERVICE as follows;
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.IBinder;
public class SMSAlertPlaybackService extends Service {
MediaPlayer player;
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
public void onStart(Intent startId, int arguments)
{
//MediaPlayer player;
super.onStart(startId, arguments);
player = MediaPlayer.create(this, R.raw.ding);
player.start();
}
public void onDestroy()
{
super.onDestroy();
player.stop();
}
}
Moreover when I am debugging it to go inside the
com.myexample.START_THE_MUSIC code, the debugger is complaining that
source code is not found.
Please help me out by giving your valuable inputs.
Thanks in advance.
Somenath Mukhopadhyay
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---