我正在尝试在Android中执行建议提供程序。根据我输入的文本(此部分已经完成)显示建议,但是当我想从内容提供程序恢复数据(其_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()))
{
...
}
}
答案 0 :(得分:0)
最后,经过尝试,尝试并尝试解决它。
我不知道为什么但是如果我写“projectionMap.put(”_ id“,”_ id“+”AS“+ SearchManager.SUGGEST_COLUMN_INTENT_DATA)”,getData()返回null但是当我使用“projectionMap.put( “idPlace”,“idPlace”+“AS”+ SearchManager.SUGGEST_COLUMN_INTENT_DATA);“getData()返回我想要的内容。
这是我的最终代码:
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("idPlace", "idPlace"+" AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA);
projectionMap.put("_id", "_id");
builder.setProjectionMap(projectionMap);
SQLiteDatabase db = clidbh.getWritableDatabase();
String[] fields = {"idPlace AS _id","name","address","idPlace"};
String where = "name like '%"+selectionArgs[0]+"%'";
row = builder.query(db, fields, where, null, null, null, "_id","3");
if (row == null) {
return null;
} else if (!row.moveToFirst()) {
row.close();
return null;
}