1. Download our Official Android App: Forums for Android!

SMS help with broadcastreceiver startintent

Discussion in 'Android Apps & Games' started by gbwien, Apr 13, 2011.

  1. gbwien

    gbwien Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Apr 13, 2011

    Apr 13, 2011
    1
    0
    5
    Hi,

    I would apprecite you help here if you can.

    I have written a simple sms application and I want to be able to display a new screen to the user when ever a new SMS arrives. I would like to do this using an Intent

    Here is the code. The problem is with the Intent within Broadcastreceive. The error is
    The constructor Intent(mySMSResult, Class<showresult>) is undefined

    Any ideas

    Thanks
    Graham
    import​
    android.os.Bundle;

    import​
    android.telephony.SmsMessage;

    import​
    android.widget.Toast;

    import​
    android.content.BroadcastReceiver;

    import​
    android.content.Context;

    import​
    android.content.Intent;

    public​
    class mySMSResult extends BroadcastReceiver {
    public static final String SMSRECEIVED = "SMSR";
    private static final String SMS_REC_ACTION = "android.provider.Telephony.SMS_RECEIVED";

    @Override

    public void onReceive(final Context context, final Intent intent) {
    if (intent.getAction().equals(mySMSResult.SMS_REC_ACTION)) {
    StringBuilder sb =
    new StringBuilder();
    Bundle bundle = intent.getExtras();
    if (bundle != null) {
    Object[] pdus = (Object[]) bundle.get(
    "pdus");
    for (Object pdu : pdus) {
    SmsMessage smsMessage = SmsMessage.createFromPdu((
    byte[]) pdu);
    sb.append(
    "body - " + smsMessage.getDisplayMessageBody() + "header -" + smsMessage.getProtocolIdentifier());

    }
    }

    Intent i = ​
    new Intent(mySMSResult.this, showresult.class);
    startActivity(i);

    }
    }

    }
     

    Advertisement

  2. Evanmg7

    Evanmg7 Lurker
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Jan 23, 2011

    Jan 23, 2011
    4
    0
    5
    Either it can't find your showresults class because it is not typed right. Maybe the 's' is capilatized or something. Or you did not update the manifest to allow for the proper intent filters.

    Without the whole project, and just that one class that is all I can suggest to you.

    -Evan
     

Share This Page

Loading...