1

I'm trying to do a Suggestion Provider in Android. The suggestions are showed depending on the text which I have entered (this part is already done) but when I want to recover the data (its _id) from the content provider, the instruction getData() returns null.

In the SuggestionProvider I give value to SUGGEST_COLUMN_TEXT_1,SUGGEST_COLUMN_TEXT_2 and 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); 

And in the SearchableActivity I use getDataString() or getData() but they return 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())) 
    { 
        ...
    } 
}

1 Answers1

0

Finally, after trying, trying and trying I solved it.

I don't know why but if I write "projectionMap.put("_id", "_id"+" AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA)", getData() returns null but when I use "projectionMap.put("idPlace", "idPlace"+" AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA); " getData() returns what I wanted.

This is my final code:

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;
}