我正在使用Skype将消息发送到我的android应用。
在Skype控制台中键入的消息是“你好,我叫j”,并以文本形式发送到android应用。 android调试器将显示消息内容,如下所示:
Skype ID:
当我打印出在android中收到的消息时,我什至看不到“ skype id:”后面的“ hello my name is j”部分。
如何获得消息的第二部分?在我看来,下面的代码并没有在skype id之后提取所有SMS对象或sms消息的后半部分。
必须对此问题有答案。
处理短信的代码如下:
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "LISTENER CALLED!!!", Toast.LENGTH_LONG).show();
if(intent.getAction().equals(SMS_RECEIVED)){
String accountHolderPhone = "";
//Toast.makeText(context, "SMS RECEIVED", Toast.LENGTH_LONG).show();
Bundle bundle = intent.getExtras();
if(bundle != null){
//get SMS objects
Object[] pdus = (Object[])bundle.get("pdus");
if(pdus.length == 0){
return;
}
//form messages into single string incase it is large and broken into many parts
SmsMessage[] messages = new SmsMessage[pdus.length];
System.out.println("Here is the length =" + pdus.length);
StringBuilder sb = new StringBuilder();
for(int i=0;i<pdus.length;i++){
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
sb.append(messages[i].getMessageBody());
}
accountHolderPhone = messages[0].getOriginatingAddress().replaceAll("\\+","");
//sender = (EditText) findViewById(R.id.email);//messages[0].getOriginatingAddress();
message = sb.toString();
// Toast.makeText(context, accountHolderPhone, Toast.LENGTH_LONG).show();
}
//Send SMS Back
//final EditText phoneNumber = (EditText) findViewById(R.id.login);
if (Build.VERSION.SDK_INT >= 23) {
if (checkPermission(context)) {
//Context context = IndexActivity.super.getApplicationContext();
// allFunctions.showToast(context,"Permission granted", 4000);
} else {
requestPermission(context);
}
}//delete this
System.out.println(">>>>>>>Here is the message:"+message+"<<<<<<<");
}
}
请告诉我。