uni-app获取短信记录
// 读取短信内容
//不同机型可能获取不全
//查看权限是否已允许
var Context = plus.android.runtimeMainActivity();
var res = plus.android.invoke("android.support.v4.app.ActivityCompat", "checkSelfPermission", Context, "android.permission.READ_SMS");
var PERMISSIONS_STORAGE = new Array();
PERMISSIONS_STORAGE.push("android.permission.READ_SMS");
// res == -1 时为询问状态,询问时会走Show 和 Hidden
if (res != "0")
{
plus.android.invoke("android.support.v4.app.ActivityCompat", "requestPermissions", Context, PERMISSIONS_STORAGE, 1);
} else {
var main = plus.android.runtimeMainActivity();
var Uri = plus.android.importClass("android.net.Uri");
var ContactsContract = plus.android.importClass('android.provider.ContactsContract');
var uri = Uri.parse("content://sms/");
var cr = main.getContentResolver();
plus.android.importClass(cr);
var cur = cr.query(uri, null, null, null, null);
plus.android.importClass(cur);
cur.moveToFirst();
while (cur.moveToNext())
{
var index_Address = cur.getColumnIndex("address");
var address = cur.getString(index_Address);
//短信内容
var index_Body = cur.getColumnIndex("body");
var body = cur.getString(index_Body);
//类型1接收 2发送
var index_Type = cur.getColumnIndex("type");
var type = cur.getString(index_Type);
console.log(address,body,type);
}
cur.close();
}
// 读取短信内容结束
本文地址:https://blog.csdn.net/qq_37902065/article/details/107555289
上一篇: java GUI编程之监听操作实例分析
下一篇: PyTorch笔记 优化器的比较