如何使用LOOKUP KEY在Android中检索联系人的详细联系信息?

时间:2019-05-12 15:35:07

标签: android cursor android-contacts loader

我尝试使用此代码,但无法从onLoadFinished方法检索数据,我有cursor.columnCount = 7和cursor.getCount = 0。每当我尝试检索数据时- cursor.getString(cursor.getColumnIndex(projection [0]))我遇到错误,说大小为0,索引为0。

private static final String[] PROJECTION =
        {
                ContactsContract.Data.PHOTO_THUMBNAIL_URI,
                ContactsContract.Data.DISPLAY_NAME,
                ContactsContract.CommonDataKinds.Phone._ID,
                ContactsContract.CommonDataKinds.Email.ADDRESS,
                ContactsContract.CommonDataKinds.Email.TYPE,
                ContactsContract.CommonDataKinds.Email.LABEL,
                ContactsContract.CommonDataKinds.Email.ADDRESS
        };
private static final int DETAILS_QUERY_ID = 0;

private static final String SELECTION = ContactsContract.Data.LOOKUP_KEY + " = ?";
private String[] selectionArgs = { "" };
String lookupKey;

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    lookupKey=getArguments().getString("LOOKUPKEY");
    getLoaderManager().initLoader(DETAILS_QUERY_ID, null, this);

}


@Override
public Loader<Cursor> onCreateLoader(int loaderId, Bundle args) {
    selectionArgs[0] = lookupKey;

    return new CursorLoader(
            getActivity(),
            ContactsContract.Data.CONTENT_URI,
            PROJECTION,
            SELECTION,
            selectionArgs,
            null
    );

}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {

}

@Override
public void onLoaderReset(@NonNull Loader<Cursor> loader) {

}

}

1 个答案:

答案 0 :(得分:0)

我将其作为答案: 您的代码似乎正确,但是传递的值不正确 而不是传递lookupKey,而是将联系人姓名传递给片段。

from pyspark.sql import Window from pyspark.sql.functions import sum,when,first w = Window.orderBy(df.id) df_with_grp = df.withColumn('grp',sum(when(df.code.isin(['A','B','C']),1).otherwise(0)).over(w)) w1 = Window.partitionBy(df_with_grp.grp).orderBy(df_with_grp.id) res = df_with_grp.withColumn('status',when(first(df_with_grp.code).over(w1) == 'A','Good') \ .when(first(df_with_grp.code).over(w1) == 'B','Bad') \ .when(first(df_with_grp.code).over(w1) == 'C','Neutral') ) 更改为private static final int CONTACT_KEY_INDEX,而不是3。这应该代表投影数组中1的索引

相关问题