Launching an application from the Contact list - android

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

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:
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:
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

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):

Related

Android Voice Actions for Messaging

I'm​ developing a small messaging app on my own and I was wondering if there is a possibility to allow the user to send messages using the Google Assistant. (Like WhatsApp and Google Allo)
Which API could I use to archive this?
Before going through the code please go through this links answer along with comments .
So as mentioned there are two types of actions that can be registered
1) Custom Action
2) System Action
Here app has been registered with TAKE A NOTE action(a system generated action).
This is registered in the Manifest to let the system know that it accepts the intents which are related to taking a note.(Hope i have not over explained it)
=== Code ===
Manifest.xml
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="com.google.android.gms.actions.CREATE_NOTE" />
<category android:name="android.intent.category.VOICE"/>
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain"/>
</intent-filter>
MainActivity.java
public class VoiceAction extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_voice_action);
Intent t = getIntent();
String s = t.getStringExtra(Intent.EXTRA_TEXT);
System.out.println("====" + s);
} }
This how i tested it
Ok Google -> take a note -> google asks me choose an app -> choose the app to be tested -> give a note or a text to it -> see your log (text you said is printed there).
I will edit the answer to meet your need exactly in some time . Hope this helps
I saw something in the WhatsApp manifest :
Apparently they are using this action :
com.google.android.voicesearch.SEND_MESSAGE_TO_CONTACTS
No trace of that in any docs...
Coincidence, I think not...
https://github.com/GigaDroid/Decompiled-Whatsapp/blob/master/AndroidManifest.xml

Android, when opening shared location, my map not visible in system choises

for example, in whatsapp someone send own location and when we click to message system opens choise dialog with map apps that can open location like google map, yandex map and others. I want that my map app also be there. Other words, I want that system recognize my app as map app and when user click to location in whatsapp or other apps my app appear in system choise dialog. How can I configure my app to open location? I searched and in forums and android documentation they recommend to use implicit intent for it. But they dont show how to configure app that shows in system choises. I heard about mime-types but in documentation there are no mime-type for location.
You need to add an intent-filter to your activity that allows it to respond to map URLs. In your Androidmanifest.xml:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="maps.google.com" />
<data android:scheme="https" android:host="maps.google.com" />
<data android:scheme="geo"/>
</intent-filter>
To retrieve the URI:
protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
Uri data = intent.getData(); // Here you will receive the URI
// ...
}
Implicit Intent's are more of like Your app to other apps sort of thing and you're aiming for the reverse version (Other apps to your app). What you are looking for is Intent Filter. As per the docs:
To allow other apps to start your activity, you need to add an <intent-filter> element in your manifest file for the corresponding <activity> element.
Cheers! :)

How to OAuth 2.0 login using Chrome custom tabs (Fitbit API)

Fitbit API doesn't support webview anymore.
So, I studied chrome custom tabs and applied in my app.
But after login, when I pressed this pink button(allow button), nothing happened.(Image below)
How can I receive access token and store it in app?
Please help me.
Thanks.
When authorizing agains the Fitbit API, you need to provide a redirect_uri, which is where the user will be taken after logging in. You need to provide a uri that will take the user back to your application.
To achieve that, create an intent filter and add a data tag with a custom scheme, such as myapplication://logincallback to the Activity you want to handle the login.
The intent filter will look something like this:
<intent-filter . . . >
<data android:scheme="myapplication" android:host="logincallback" />
. . .
</intent-filter>
Now, set the redirect_uri as mypplication://logincallback to the authorization step of the flow, and when the user clicks the pink button, it should open the Activity you added the intent filter.
You will be able to retrieve the parameters inside your activity by calling getData on the Intent.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="logincallback"
android:pathPattern=".*"
android:scheme="myapp" />
</intent-filter>
Suppose you have redirect_uri myapp://logincallback, then add above code in your activity in Manifest xml file and it will work.

Launch android app when a link is tapped on SMS

I don't know if many people have tried this but I am trying a build an app that requires user to tap on a link on the sms he/she receives and this will launch the android app. Is it possible to do in android? If yes, how can I do this? I know this can be done in IOS. Any suggestions or help will be appreciated. Thank You.
In you Manifest, under an Activity that you want to handle incoming data from a link clicked in the messaging app, define something like this:
<activity android:name=".SomeActivityName" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="com.your_package.something" />
</intent-filter>
</activity>
The android:scheme="" here is what will ensure that the Activity will react to any data with this in it:
<data android:scheme="com.your_package.something" />
In the SomeActivityName (Name used as an illustration. Naturally, you will use your own :-)), you can run a check like this:
Uri data = getIntent().getData();
String strData = data.toString();
if (strScreenName.equals("com.your_package.something://")) {
// THIS IS OPTIONAL IN CASE YOU NEED TO VERIFY. THE ACTUAL USAGE IN MY APP IS BELOW THIS BLOCK
}
My app's similar usage:
Uri data = getIntent().getData();
strScreenName = data.toString()
.replaceAll("com.some_thing.profile://", "")
.replaceAll("#", "");
I use this to handle clicks on twitter #username links within my app. I need to strip out the com.some_thing.profile:// and the # to get the username for further processing. The Manifest code, is the exact same (with just the name and scheme changed).
Add an intent-filter to your app that listens for links that follow the format you want your app to be launched on.
However, this will be a global listener, and any link that fits the format even outside the SMS app will trigger your app. So if the user taps a similar link in the web browser, your app will attempt to respond to it.
Additionally, if there is another app besides yours that can handle this link, Android will create a chooser that allows the user to pick whichever app they want to use. There is nothing you can do about this, except suggest that the user make your app the default handler for such links.
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"
<data android:scheme="https" android:host="${hostName}" android:pathPattern="/.*" />
</intent-filter>
Previous answers are OK but don't forget to specify the pattern.
See more details here.
Also define your hostname inside Gradle file like:
android {
defaultConfig {
manifestPlaceholders = [hostName:"subdomain.example.com"]
}
}
More info about manifestPlaceholders here.

Android Intent launch from browser

This topic has been covered before, but I can't find an answer specific to what I'm asking.
Where I am: I followed hackmod's first piece of advice here: Make a link in the Android browser start up my app? and got this to work with a link in the webpage.
However, I'm having trouble understanding the second option (intent uri's). here's what I've got:
<activity android:name="com.myapps.tests.Layout2"
android:label="Auth Complete"
>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="mydomain.com"
android:path="/launch" />
</intent-filter>
</activity>
Now, with that I can go to "mydomain.com/launch" and it launches my activity. this all works well, except that I get the chooser. what I want is for it to just launch my activity without giving options.
From the explanation in the post I referenced it looks like thats what intent uris are for,but I can't find a straightforward example. what should my link in my webpage look like in order to launch this with no chooser?
I've seen a couple of examples that look something like this:
<a href="intent:#Intent;action=com.myapp.android.MY_ACTION;end">
However, that doesn't seem to work when I try it.
My test device is a Galaxy Tab 2.
any help would be appreciated.
I was also trying to launch the app in the recomended way. The following code worked for me.
Code inside the <activity> block of YourActivity in AndroidManifest.xml :
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="your.activity.namespace.CUSTOMACTION" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Code in the activities onCreate() method :
Intent intent = getIntent();
if(intent != null && intent.getAction() == "your.activity.namespace.CUSTOMACTION") {
extraValue = intent.getStringExtra("extraValueName");
Log.e("AwseomeApp", "Extra value Recieved from intent : " + extraValue);
}
For the code in HTML, write an intent for launching the specific Activity, with the action your.activity.namespace.CUSTOMACTION, and your application package name your.activity.namespace. Your can also put some extra in the intent. For example intent.putExtra("extraValueName", "WOW"). Then get the required URL by printing the value of intent.toUri(Intent.URI_INTENT_SCHEME) in the Log. It should look like :
intent:#Intent;action=your.example.namespace.CUSTOMACTION;package=your.example.namespace;component=your.example.namespace/.activity.YourActivity;S.extraValueName=WOW;end
So your HTML code should look like :
<a href="intent:#Intent;action=your.example.namespace.CUSTOMACTION;package=your.example.namespace;component=your.example.namespace/.activity.YourActivity;S.extraValueName=WOW;end">
Launch App
</a>
This is as per what #hackbod suggested in here and this page from developers.google.com.
Depending on your intent filter this link should work:
start my app
But you should note that the android system will ask the user if your app or any other browser should be started.
If you want to avoid this implement a custom protcol handler. So just your app will listen for that and the user won't get the intent chooser.
Try to add this data intent:
<data android:scheme="mycoolapp" android:host="launch" />
With the code above this link should work:
start my app
I needed a small change to abhishek89m'a answer to make this work.
<a href="intent:#Intent;action=your.example.namespace.CUSTOMACTION;package=your.example.namespace;component=your.example.namespace/.YourActivity;S.extraValueName=WOW;end">
Launch App
</a>
I removed ".activity" after the slash in component name.
And I want to add, that custom action is probably the best answer to this problem if you don't want the app chooser to show up.
p.s. I would add this as comment, but I'm a new user and I don't have enough reputation points.
<a href="your.app.scheme://other/parameters/here">
This link on your browser will launch the app with the specific schema
like that on your intent
<intent-filter>
<data android:scheme="your.app.scheme" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>

Categories

Resources