本文介绍了Android应用程序是不是真实设备会自动发送短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经开发了一个Android应用程序,可以自动将自动发送短信到它接收短信的设备。
I have developed an android app that automatically sends an SMS automatically to a device from which it receives an SMS.
我的应用程序正在模拟器正常,但当我真正的设备(Android手机)上运行它,那么它只接收短信,不自动发送效应初探。
My App is working fine on the emulator but when I run it on a real device (android mobile) then it only receives SMSs and does not sends a reponse automatically.
我的code是如下:
public class SMSReciever extends BroadcastReceiver {
String address;
String smsMe = "I Recieved Your SMS";
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
Object messages[] = (Object[]) bundle.get("pdus");
SmsMessage smsMessage[] = new SmsMessage[messages.length];
for (int n = 0; n < messages.length; n++) {
smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
address = smsMessage[n].getOriginatingAddress();
}
Toast toast = Toast.makeText(context,"Received SMS: " +
smsMessage[0].getMessageBody(), Toast.LENGTH_LONG);
toast.show();
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(address, null, smsMe, null, null);
}
}
我不知道是什么问题。以及为什么它没有正确真实的设备上工作。
I don't know what is the problem. And why it is not working properly on a real device.
推荐答案
试试这个code发送短信。
Try this code to send sms.
//---sends an SMS---
private void sendSMS(String phoneNumber, String message)
{
PendingIntent pi = PendingIntent.getActivity(this, 0,
new Intent(this, class_name.class), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, pi, null);
}
}
这篇关于Android应用程序是不是真实设备会自动发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!