我刚开始使用Android开发和构建SMS应用程序 我学会了编写收件箱代码,但想显示对话内容!
这就是我获取收件箱短信的方式
SmsList = findViewById(R.id.SmsList) ;
// Create Inbox box URI
Uri inboxURI = Uri.parse("content://sms/inbox");
// List required columns
String[] reqCols = new String[] { "_id", "address", "body" };
// Get Content Resolver object, which will deal with Content Provider
ContentResolver cr = getContentResolver();
// Fetch Inbox SMS Message from Built-in Content Provider
Cursor c = cr.query(inboxURI, reqCols, null, null, null);
// Attached Cursor with adapter and display in listview
adapter = new SimpleCursorAdapter(this, R.layout.row, c,
new String[] { "body", "address" }, new int[] {
R.id.lblMsg, R.id.lblNum });
SmsList.setAdapter(adapter);
}
下面是我的row.xml!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content"
android:padding="10dp">
<TextView
android:textSize="20sp"
android:layout_width="wrap_content"
android:id="@+id/lblNum"
android:layout_marginLeft="20dp"
android:layout_height="match_parent"
android:gravity="start"/>
<TextView
android:textSize="17sp"
android:layout_width="wrap_content"
android:maxLines="2"
android:id="@+id/lblMsg"
android:layout_marginLeft="20dp"
android:layout_height="match_parent"
android:gravity="start"/>