Possible Duplicate:
How do I pass data from a BroadcastReceiver through to an Activity being started?
In my Android application, I have a main activity called App
and a BroadcastReceiver called SmsReceiver
. Inside the onReceive()
method of SmsReceiver
, I want catch an SMS and send its contents back to App
. I don't know how to do this, though. Would this be done with a class inside App
? I have tried doing this, and adding that class's name to the AndroidManifest, but upon trying to call it, the application crashed with an error saying that this class could not be instantiated.
(I am aware that this question has been posted before, but I haven't seen any satisfying answers on them.)
Edit, to illustrate the solution I tried:
In the AndroidManifest, I added this:
<receiver android:name=".App.SmsHandler" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
In the App class, I added:
public class SmsHandler extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
// Stuff here
}
}
and
public static final String TEXT_INTENT = "textintent";
I tried to call it using the following code (in SmsReceiver
but this made the app crash):
private void forwardSms(Message message, Context context) {
Intent myIntent = new Intent(MsgWallApp.TEXT_INTENT);
Bundle myData = new Bundle();
myData.putString("sender", message.getSender());
myData.putString("text", message.getText());
context.sendBroadcast(myIntent);
}