android获取短信
‘壹’ android studio开发怎么获取手机短信
1.点击一个按钮就会显示系统的联系人列表,当用户点击联系人之后就会看到详细的名字和电话。
2.具体的代码如下:首先在AndroidManifest.xml文件中配置用户权限。
<uses-permission android:name="android.permission.READ_CONTACTS"/>11
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.dragon.testevent.MainActivity">
‘贰’ android 6.0 读取短信需要动态权限吗
这类的权限不需要动态申请,需要这个权限的时候还是按照以往的做法,在清单文件中申请相应的权限即可,在安装的时候会展示给用户,用户同意安装就获取相应的权限。写法举例如下:
清单文件中:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.deepai.paipai">
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
........
‘叁’ android自动获取短信验证码有什么安全隐患
自动获取短信验证码,那么这个应用肯定获取到了读取你短信的权限,所以安全隐患就在它可以得到你所有的短信信息
‘肆’ android开发怎样获取系统短信指定内容求大神啊!
Java代码
// android获取短信所有内容
// 注意设置权限[添加到AndroidMainfest.xml] <uses-permission android:name="android.permission.READ_SMS" />
public String getSmsInPhone()
{
final String SMS_URI_ALL = "content://sms/";
final String SMS_URI_INBOX = "content://sms/inbox";
final String SMS_URI_SEND = "content://sms/sent";
final String SMS_URI_DRAFT = "content://sms/draft";
StringBuilder smsBuilder = new StringBuilder();
try{
ContentResolver cr = getContentResolver();
String[] projection = new String[]{"_id", "address", "person",
"body", "date", "type"};
Uri uri = Uri.parse(SMS_URI_ALL);
Cursor cur = cr.query(uri, projection, null, null, "date desc");
if (cur.moveToFirst()) {
String name;
String phoneNumber;
String smsbody;
String date;
String type;
int nameColumn = cur.getColumnIndex("person");
int phoneNumberColumn = cur.getColumnIndex("address");
int smsbodyColumn = cur.getColumnIndex("body");
int dateColumn = cur.getColumnIndex("date");
int typeColumn = cur.getColumnIndex("type");
do{
name = cur.getString(nameColumn);
phoneNumber = cur.getString(phoneNumberColumn);
smsbody = cur.getString(smsbodyColumn);
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd hh:mm:ss");
Date d = new Date(Long.parseLong(cur.getString(dateColumn)));
date = dateFormat.format(d);
int typeId = cur.getInt(typeColumn);
if(typeId == 1){
type = "接收";
} else if(typeId == 2){
type = "发送";
} else {
type = "";
}
smsBuilder.append("[");
smsBuilder.append(name+",");
smsBuilder.append(phoneNumber+",");
smsBuilder.append(smsbody+",");
smsBuilder.append(date+",");
smsBuilder.append(type);
smsBuilder.append("] ");
if(smsbody == null) smsbody = "";
}while(cur.moveToNext());
} else {
smsBuilder.append("no result!");
}
smsBuilder.append("getSmsInPhone has executed!");
} catch(SQLiteException ex) {
Log.d("SQLiteException in getSmsInPhone", ex.getMessage());
}
return smsBuilder.toString();
}