Java 我建立了短信阅读应用程序,但它启动,但不获取短信

Java 我建立了短信阅读应用程序,但它启动,但不获取短信,java,android,android-broadcastreceiver,Java,Android,Android Broadcastreceiver,这是我的主java文件,我使用短信内容提供商为获取短信而构建,并希望在我的应用程序中显示。但由于某些原因,应用程序启动时没有出现任何错误,但它会在我的手机上显示短信。它显示了所有的按钮和列表视图,所有都是正确的,但它应该显示的短信内容不存在 package com.smsapp; import android.app.Activity; import android.content.ContentResolver; import android.database.Cursor; import

这是我的主java文件,我使用短信内容提供商为获取短信而构建,并希望在我的应用程序中显示。但由于某些原因,应用程序启动时没有出现任何错误,但它会在我的手机上显示短信。它显示了所有的按钮和列表视图,所有都是正确的,但它应该显示的短信内容不存在

package com.smsapp;

import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
 import android.widget.Button;
 import android.widget.ListView;
 import android.widget.SimpleCursorAdapter;
 import android.widget.TextView;

   public class MainActivity extends AppCompatActivity implements OnClickListener {

// GUI Widget
Button btnSent, btnInbox, btnDraft;
TextView lblMsg, lblNo;
ListView lvMsg;

// Cursor Adapter
SimpleCursorAdapter adapter;

/**
 * Called when the activity is first created.
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Init GUI Widget
    btnInbox = (Button) findViewById(R.id.btnInbox);
    btnInbox.setOnClickListener(this);

    btnSent = (Button) findViewById(R.id.btnSentBox);
    btnSent.setOnClickListener(this);

    btnDraft = (Button) findViewById(R.id.btnDraft);
    btnDraft.setOnClickListener(this);

    lvMsg = (ListView) findViewById(R.id.lvMsg);

}

@Override
public void onClick(View v) {

    if (v == btnInbox) {

        // 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.lblNumber});
        lvMsg.setAdapter(adapter);

    }

    if (v == btnSent) {

        // Create Sent box URI
        Uri sentURI = Uri.parse("content://sms/sent");

        // List required columns
        String[] reqCols = new String[]{"_id", "address", "body"};

        // Get Content Resolver object, which will deal with Content
        // Provider
        ContentResolver cr = getContentResolver();

        // Fetch Sent SMS Message from Built-in Content Provider
        Cursor c = cr.query(sentURI, 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.lblNumber});
        lvMsg.setAdapter(adapter);

    }

    if (v == btnDraft) {
        // Create Draft box URI
        Uri draftURI = Uri.parse("content://sms/draft");

        // List required columns
        String[] reqCols = new String[]{"_id", "address", "body"};

        // Get Content Resolver object, which will deal with Content
        // Provider
        ContentResolver cr = getContentResolver();

        // Fetch Sent SMS Message from Built-in Content Provider
        Cursor c = cr.query(draftURI, 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.lblNumber});
        lvMsg.setAdapter(adapter);

    }

   }
}
//这是我的第一个XML文件活动\u main:

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0">

    <Button
        android:id="@+id/btnInbox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.5"
        android:text="Inbox"></Button>

    <Button
        android:id="@+id/btnSentBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.5"
        android:text="Sent Box"></Button>

    <Button
        android:id="@+id/btnDraft"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.5"
        android:text="Draft"></Button>
</LinearLayout>

 <ListView
    android:id="@+id/lvMsg"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"></ListView>

 </LinearLayout>

//这是我的第二行XML文件:

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="TextView" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:id="@+id/lblMsg">                      </TextView>
<TextView android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="TextView" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:textColor="#00f"
    android:id="@+id/lblNumber"></TextView>


您用于SimpleCrsorAdapter的构造函数已从API级别11(蜂巢)中弃用。你的目标版本是什么?更多长官,我的目标sdk版本是24