why the implicit intent in NotesList can't pass the intent-filter of my activity ?
The sample NotesList(given by google,see it here: Note Pad) shows how to use intent filters.
In NotesList.java,this activity create a option menu and the menu add menu items based on available activities that accept an intent like this :
@Override
public boolean onCreateOptionsMenu(Menu menu){
super.onCreateOptionsMenu(menu);
// Create an Intent that describes the requirements to fulfill, to be included
// in our menu. The offering app must include a category value of Intent.CATEGORY_ALTERNATIVE.
Intent intent = new Intent(null, dataUri);
intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
// Search and populate the menu with acceptable offering applications.
menu.addIntentOptions(
R.id.intent_group, // Menu group to which new items will be added
0, // Unique item ID (none)
0, // Order for the items (none)
this.getComponentName(), // The current activity name
null, // Specific items to place first (none)
intent, // Intent created above that describes our requirements
0, // Additional flags to control items (none)
null); // Array of MenuItems that correlate to specific items (none)
return true;
}
The detail of this content is like this:
Action:null Type:null Data(uri):content://com.google.provider.NotePad/notes Category:android.intent.category.ALTERNATIVE
I want my activit开发者_运维百科y to be included in the menu,and the intent filter of my activity is like this:
<intent-filter android:label="hello filter">
<action android:name="android.intent.action.INSERT" />
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="content" android:host="com.google.provider.NotePad"
android:path="notes" />
</intent-filter>
it does not work.while if I change data into :
< data android:mimeType="vnd.android.cursor.dir/vnd.google.note" / >
,it works.
It puzzled me because according to intents-filters:
An Intent object that contains a URI but no data type (and a type cannot be inferred from the URI) passes the test only if its URI matches a URI in the filter and the filter likewise does not specify a type. This will be the case only for URIs like mailto: and tel: that do not refer to actual data.
The intent in notesList only contains a URI(content://com.google.provider.NotePad/notes) and no data type,in My first intent filter,The uri matches the intent's uri,it should work but no,any one can explain why?
Thanks.
You quoted the right paragraph, it says "This will be the case only for URIs like mailto: and tel: that do not refer to actual data.". But the the content:
URI definitely refers to data, therefore you have to specify the type.
精彩评论