联系人不断崩溃

时间:2018-01-30 14:25:05

标签: android

通讯录不断崩溃

public class MainActivity extends AppCompatActivity {
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Uri allContacts= Uri.parse("content://contacts/people");
    Cursor c=managedQuery(allContacts,null,null,null,null);

    String[] columns=new String[]{
            ContactsContract.Contacts.DISPLAY_NAME,ContactsContract.Contacts._ID};
    int[] views=new int[]{R.id.ContactsName,R.id.ContactsID};
    SimpleCursorAdapter adaptor=new SimpleCursorAdapter(this,R.layout.activity_main,c,columns,views);
    ListView listView=(ListView)findViewById(R.id.ListView);
    listView.setAdapter(adaptor);

"尝试运行,它显示联系人在Naugat Android 7中不断崩溃"

我是Android新手.. 提前谢谢......

1 个答案:

答案 0 :(得分:0)

将此行添加到<manifest>标记之间的AndroidManifest.xml文件中:

<uses-permission android:name="android.permission.READ_CONTACTS"/>