aha.... what i can or cannot do from the broadcastreceiver ? I am
trying to send an sms , and i get an exception
android.app.ReceiverRestrictedContext !
public class OnetimeAlarmReceiver extends BroadcastReceiver {
private AlarmExample currentContext = null;
@Override
public void onReceive(Context context, Intent intent) {
try {
Toast.makeText(context, "Alarm worked.",
Toast.LENGTH_LONG).show();
currentContext = (AlarmExample)context;
sendSMS("9993914386", "Your SMS.");
}
catch(Exception e) {
Log.d("RemindMe", e.getMessage());
}
}
// ---sends an SMS message to another device---
private void sendSMS(String phoneNumber, String message) {
PendingIntent pi = PendingIntent.getActivity(currentContext, 0,
new
Intent(currentContext,
OnetimeAlarmReceiver.class), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, pi, null);
}
On Dec 9, 12:07 pm, "Mark Murphy" <[email protected]> wrote:
> > Now, that i m able to display this oast, how can I start my activity ?
> > like the normal way we call one activity from another ?
>
> I do not recommend starting an activity from a BroadcastReceiver or
> Service. Users will get rather irritated if, in the middle of doing
> something else, your activity takes over the screen.
>
> Use a Notification instead, to put an icon in the status bar, to let the
> user know there is something that needs their attention.
>
> --
> Mark Murphy (a Commons Guy)http://commonsware.com
> Android App Developer Books:http://commonsware.com/books.html
--
You received this message because you are subscribed to the Google
Groups "Android Developers" 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-developers?hl=en