问题
I want to write application which is connected with Contacts.
Scenario :
- Enter to phone Contacts
We choose Contact item

And icon of my application should appear in QuickAction Dialog.
- I click on my app icon and Aplication start with data from contact record.
What I have to add to AndroidManifest to do it?
回答1:
Add this intent filter for your app to be visible for all contacts.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/name" />
</intent-filter>
Change the mimetype, so that only contacts with a particular data have your activity.
e.g if you want your activity to show only for contacts with email then change mimetype to vnd.android.cursor.item/email_v2 . You can get the mimetype names from the subclasses of DataColumns
回答2:
Exactly this behavior is possible only when your app in an only app on users device which is capable to process desired type of content. For example, if you want to use type of content "send SMS", or "make a phone call" - your app most likely is not the only app on the device which can process such actions (there are also stock phone dialer and SMS apps).
Anyway, you can always add your application to the list of apps which will appear when user clicks to that quick actions. It will look like this:
In order to do this, you need:
specify in your manifest file that your application is capable to deal with desired action, for example "sending SMS". To do this you need to add intent filter to your Activity, that you wish to be called in that case:
<intent-filter> <action android:name="android.intent.action.SENDTO" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="sms" /> <data android:scheme="smsto" /> </intent-filter>in your target Activity add code, that process desired content type. In your target Activity
onCreate()method, oronNewIntent()method query data string parameter from calling Intent. Here is some sample code to demonstrate general idea:public class MyActivity extends Avtivity { @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); String dataStr = intent.getDataString(); // do some processing with dataStr } @Override protected void onCreate(Bundle savedInstanceState) { Intent callIntent = getIntent(); String dataStr = callIntent.getDataString(); // do some processing with dataStr } }
来源:https://stackoverflow.com/questions/12383692/predefined-actions-of-application-link-to-my-application-from-contacts
