设为首页 加入收藏

TOP

Android处理网页的短信链接
2014-11-24 03:14:27 来源: 作者: 【 】 浏览:2
Tags:Android 处理 网页 短信 链接

这里我是这样实现同时显示号码和短信内容的,请参考一下代码:


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);
}
}


对于有的链接,可能是不标准的,比如上述代码中有的会出现两个” ”,不过这个也能处理。当然根据自己的情况实现自己的处理逻辑。


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Java中数组的比较的真相 下一篇iOS 从相机或相册获取图片并裁剪

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·请问微信4.0版本xwec (2025-12-24 22:48:42)
·电脑NVIDIA的文件夹 (2025-12-24 22:48:40)
·如何看待微信新版本 (2025-12-24 22:48:37)
·C语言中如何将结构体 (2025-12-24 22:20:09)
·纯C语言结构体成员变 (2025-12-24 22:20:06)