我正在尝试在 Android 中做一个 Suggestion Provider。根据我输入的文本显示建议(这部分已经完成),但是当我想从内容提供者恢复数据(它的_id)时,getData() 指令返回 null。
在 SuggestionProvider 中,我给 SUGGEST_COLUMN_TEXT_1、SUGGEST_COLUMN_TEXT_2 和 SUGGEST_COLUMN_INTENT_DATA_ID 赋值:
HashMap<String,String> map = new HashMap<String,String>();
SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
builder.setTables("place");
Map<String, String> projectionMap = new HashMap<String, String>();
projectionMap.put(Place.COL_NAME, Place.COL_NAME+" AS " + SearchManager.SUGGEST_COLUMN_TEXT_1);
projectionMap.put(Place.COL_ADDRESS, Place.COL_ADDRESS+" AS " + SearchManager.SUGGEST_COLUMN_TEXT_2);
projectionMap.put("_id", "_id" + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID);
projectionMap.put("_id", "_id");
builder.setProjectionMap(projectionMap);
在 SearchableActivity 我使用 getDataString() 或 getData() 但它们返回 null:
private void handleIntent(Intent intent)
{
if (Intent.ACTION_VIEW.equals(intent.getAction()))
{
Log.w("test",intent.getDataString()+"a");
}
else if (Intent.ACTION_SEARCH.equals(intent.getAction()))
{
...
}
}