Predefined application actions. Link to my application from contacts

I want to write an application that is related to contacts.

Scenario:

  • Entering the phone Contacts
  • We choose a contact item. enter image description here

  • And the icon of my application should appear in the QuickAction dialog box.

  • I click on the icon of my application and Aplication runs the data from the contacts record.

What should I add to AndroidManifest for this?

+4
source share
2 answers

Add this intent filter so that your application is visible to 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 type so that your contacts only have contacts with specific data.

For example, if you want your activity to be shown only for email contacts, change mimetype to vnd.android.cursor.item/email_v2 . You can get mimetype names from subclasses of DataColumns

+4
source

It is this behavior that is possible only when your application is in a single application on a user device that is capable of processing the desired type of content. For example, if you want to use the content type “send SMS” or “make a phone call”, your application is most likely not the only application on the device that can handle such actions (there is also a phone number and SMS applications).

In any case, you can always add your application to the list of applications that will appear when the user clicks on these quick actions. It will look like this:

List of apps for content type

For this you need:

  • indicate in your manifest file that your application is capable of handling the desired action, such as sending SMS. To do this, you need to add a target filter to your activity, which you want to call in this 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 application, add code that processes the desired type of content. In your target Activity onCreate() or onNewIntent() method, enter the parameter string of the method request data from the Intent call. Here is a sample code to demonstrate a 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 } } 
+4
source

Source: https://habr.com/ru/post/1433729/


All Articles