2

Im looking for a way to make a link between contact and Android Application. An example of this is Whatsapp, this application binds to a contact and makes it possible to launch the whatsapp application with the number as parameter. I have not been able to find a way of accomplishing this, and was wondering if there was someone with expierence in this area.

Your help is very much appreciated

Martijn de Langh
  • 405
  • 3
  • 16
  • While I agree with the answer pointing you to the ``, I am very skeptical that the `` the answer provides is a good one to use. If you already have Whatsapp installed, install [the App Browser app](https://play.google.com/store/apps/details?id=com.japanesecrackers.appbrowser), and you can examine the Whatsapp manifest to see what they might have in there that would tie them to a contacts app. – CommonsWare Oct 03 '14 at 00:15
  • I think `intent-filter` is definitely the right way to achieve this. I am quite sure it is - at least part of - WhatsApps solution. – DaniEll Oct 03 '14 at 05:28

2 Answers2

1

Intent-Filter is the way to go!

In your AndroidManifest.xml you have to tell Android that your app can respond to such an Intent.
Example:

 <application ... >
    <activity ... >
        <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>
    </activity>
</application>

Than your Activity can access the Intents data when called.
Example:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // get intent-data
    Intent intent = getIntent();
    if (Intent.ACTION_SENDTO.equals(intent.getAction())) {
        Toast.makeText(this, intent.getDataString(), Toast.LENGTH_LONG).show();
    }
    // close activity
    finish();
}

With this code you can choose your App as the receiver whenever another App (e.g. Contacts) fires such an Intent.
Example to fire such an Intent (Screenshot from Contacts):
Screenshot from Contacts

DaniEll
  • 1,022
  • 4
  • 22
  • 31
  • Thank you for your answer, I am sure the use of intent filters is the way to go, but the filter that I have to use is for me unclear. In your example you are adding a listener to the SendText button, but I do not want to override the users capability of using the textbutton. I would like an extra button like an app as whatsapp is using – Martijn de Langh Oct 06 '14 at 12:42
1

I didn't try this, but I hope my answer will be helpful for you.

To clarify, you want your app was in the 'Connections' section as Whatsapp app:
enter image description here

In this case, you should use Account Manager If you go to the phone Settings in the "Accounts and Sync" you should see all of the custom accounts registered on your phone: enter image description here

Sorry, for not providing exact code snippets, but I hope this was useful for you, and you can Google your question (looking for Account Manager). Maybe these links will be useful for you too:

create custom account android
Custom Account Type with Android AccountManager

Community
  • 1
  • 1
krossovochkin
  • 12,030
  • 7
  • 31
  • 54
  • 1
    This is exactly what I was looking for, with this information I found the following link that adds code to your answer: http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-2/ – Martijn de Langh Oct 08 '14 at 10:13