获取短信代码;
async getMessage() {
//不同机型可能获取不全
//查看权限是否已允许
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");
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();
var smslist = [];
//console.log(cur);
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);
smslist.push({
address:address,
body:body,
type:type
})
}
this.smslist=JSON.stringify(smslist)
// console.log(JSON.stringify(smslist));
},