在Android Wear中显示联系人列表

时间:2015-11-20 12:34:09

标签: android wear-os android-contacts

我想使用Sony Smartwatch 3访问Android Wear中的联系人。 我可以在智能手表中看到STARRED触点,但我无法在磨损活动中显示它们。

权限在清单文件中设置。

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

我尝试了两种方法但没有成功:

1:

Cursor cursor;

cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

Log.v("MyActvt", "**********************NMB OF RAW = " + cursor.getCount());
/* the result is 0 in the previous Log.v*/

/* Then off course it does not enter the loop */
while (cntcts.moveToNext()) { 

                String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
                String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

}

2:

使用以下代码启动活动时也是如此。智能手表屏幕显示“无应用程序可以执行此操作”

int PICK_CONTACT = 2;

Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT);

@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
        super.onActivityResult(reqCode, resultCode, data);
        Log.v("MYActivity", "**********************RESULT CODE = "+resultCode);
        if (reqCode == PICK_CONTACT) {
            if (resultCode == Activity.RESULT_OK) {
                Uri contactData = data.getData();
                Cursor cursor = getContentResolver().query(contactData, null, null, null, null);
                if (cursor.moveToFirst()) {
                    String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
                    String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                }
             }
        }
}

你有什么想法或者之前是否看到过这个问题?

非常感谢

0 个答案:

没有答案