Он говорит null к моему сообщению, и я хочу взять сообщение, которое пишу из другого класса, возможно ли это? Может ли кто-нибудь помочь узнать, в чем моя ошибка? Я попытался кнопка перемещение этого класса тоже, но это не будет работать либо,Почему мой автоматический ответ не отправляет смс?
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;
}
}
Какое значение вы получаете после этого вызова getContactName. Вы видите какую-то ценность? – Shiv
Почему вы используете 'findViewById' в' BroadcastReceiver'? –
@Shiv: да, есть код, который я удаляю из этого, потому что он слишком длинный, вы хотите его увидеть? я могу опубликовать его. да, я вижу значение из getContactName, проблема в том, когда я получил сообщение, мое сообщение, которое я пишу из другого xml-файла, не отправляет его обратно, он говорит null – noob