这里我是这样实现同时显示号码和短信内容的,请参考一下代码:
package ps.androidyue.demo.send_sms;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
public class SendSMSDemoActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//短信超链接的内容,包含号码和短信内容
String s = "sms:106901956100041 body=wmm%E6%96%B0%E5%AF%86%E7%A0%81";
//获取短信号码,包含"sms:"
String address = s.contains(" ") s.substring(0, s.indexOf(" ")) : s;
//获取短信内容,如果没有则为""
String body = s.replaceAll(address, "");
body = body.contains("=") body.substring(body.indexOf("=") + 1) : body;
//对于中文内容进行Uri解码
body = Uri.decode(body);
Uri smsToUri = Uri.parse(address);// 联系人地址
Intent mIntent = new Intent(android.content.Intent.ACTION_SENDTO,smsToUri);
//设置短信的内容
mIntent.putExtra("sms_body", body);
startActivity(mIntent);
}
}
对于有的链接,可能是不标准的,比如上述代码中有的会出现两个” ”,不过这个也能处理。当然根据自己的情况实现自己的处理逻辑。