为什么我的自动回复不发送短信?

时间:2015-01-06 01:55:38

标签: android sms

它对我的消息说空了,我想要从另一个类写的消息,是否可能?任何人都可以帮忙看看我的错误是什么?我也尝试过将按钮移到这个课程,但它也不会工作,

public class ReceiveMessage extends BroadcastReceiver { 

private Button btnchange;
EditText qwer;
private Context ctx;
EditText text;
TextView asd;


static TextView messageBox;
static String phoneNumber;
private EditText pesan;

public void onReceive(Context context, Intent intent) {

    Bundle bundle = intent.getExtras();
    if (bundle != null) {
        Object[] messages = (Object[]) bundle.get("pdus");
        SmsMessage[] sms = new SmsMessage[messages.length];

        for (int n = 0; n < messages.length; n++)

        {
            sms[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
            break;
        }

        for (SmsMessage msg : sms)              
        {           
            String msga = msg.getMessageBody();
            String phoneNumber1 = msg.getOriginatingAddress();
            String name = getContactName(context, phoneNumber1);

            if (name != null && !name.equals("null"))

            {
                SmsManager smsManager = SmsManager.getDefault();

                String sendTo = phoneNumber1;

 // i want to locate my message that i write from another class
                asd = (TextView) findViewById (R.id.textView1);
                qwer = (EditText) findViewById (R.id.editText1);


            try {                       
// here's the message that i want to send but the program says null inside my msg 
                String smsMessage = "Hi " +name+ "\n\n" +qwer.getText().toString()+ "\n\nThx";

                smsManager.sendTextMessage(sendTo, null, smsMessage, null,
                        null);  

            }catch(Exception ex){
                ex.printStackTrace();
                System.out.println("errror karena " +ex.getMessage());
            }


            }

            }

    }
    private EditText findViewById (int e) {

    return  null;
}

}

1 个答案:

答案 0 :(得分:0)

您无法从此类访问另一个类膨胀视图。 您需要检查是否已在清单中声明此接收器。 看看这个堆栈溢出问题。 Android - SMS Broadcast receiver