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
Related
I am trying to open location settings from Chrome (on Android) on a button click using Android Intents. I am following the Barcode Scanner example and tried encoding the url similar way.
For location I have tried this:-
const uri = "intent://com.google.android.gms.location.settings.GOOGLE_LOCATION_SETTINGS#Intent;action=com.google.android.gms.location.settings.GOOGLE_LOCATION_SETTINGS;end"
I also tried opening settings using this:-
const uri = "intent://ACTION_SETTINGS#Intent;action=android.provider.Settings.ACTION_SETTINGS;end"
or this
const uri = "intent://android.provider.Settings.ACTION_SETTINGS#Intent;action=android.provider.Settings.ACTION_SETTINGS;end"
But nothing seems to work. Any help is appreciated.
I am attaching it to a button using href tag.
Seems you can't open Location Settings directly from Android Intents with Chrome because Settings Activities didn't support BROWSABLE category (for details take a look at this question of Dickeylth and answer of Rafal Malek). But You can 100% do this via custom android application and Deep Links to custom Activity with <category android:name="android.intent.category.BROWSABLE"/> support, like in that tutorial.
In that case your application SettingsActivity code should be like:
public class SettingsActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
}
}
and AndroidManifest.xml part for SettingsActivity
<activity android:name=".SettingsActivity">
<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="open.location.settings"
android:scheme="http"/>
</intent-filter>
</activity>
and, finally, "deep" link for SettingsActivity in HTML file:
Open Location Settings
Seems, if you don't want to install app on user side, you can also do this in Instant Apps. Details for links to Instant App you can find here.
We are trying to implement Google's App Indexing feature. We've added the deep links to our website with the rel-alternate tag in the following format:
android-app://id.of.the.app/scheme/?screen=Product&product=123456
Now we get content mismatch crawling errors. If I use the QR code for testing from here everything works fine. But if I open a crawling error, click on "Open App Page" and use the adb command for testing I can see that everything starting from the ampersand doesn't get passed to the app and therefore my product data cannot be loaded. I suspect that's how the crawler checks the content of the app and that's why we get Content Mismatch Errors.
Also if I use the "Fetch as Google" from the Search Console it looks like everything from the ampersand gets cut off.
I checked on eBay as it is working with their app and that's the link they are using:
android-app://com.ebay.mobile/ebay/link/?nav=item.view&id=221559043026&referrer=http%3A%2F%2Frover.ebay.com%2Froverns%2F1%2F711-13271-9788-0%3Fmpcl%3Dhttp%253A%252F%252Fwww.ebay.com%252Fitm%252FRoxy-Fairness-Backpack-Womens-Red-RPM6-%252F221559043026%253Fpt%253DLH_DefaultDomain_0
They have encoded the ampersand with & but if I do that and test it with the "Fetch as Google" function it doesn't work either.
These users seem to have the same issue, but they didn't share a solution (if they found one):
https://productforums.google.com/forum/#!msg/webmasters/5r7KdetlECY/enYknTVkYU4J
https://productforums.google.com/forum/#!topic/webmasters/lswyXKlS-Ik
I'm thankful for any ideas.
Update 1
That's how I'm interpreting the deep link inside the Android app:
Uri data = getIntent().getData();
String scheme = data.getScheme();
if (scheme.equals("scheme")) {
String screen = data.getQueryParameter("screen");
if (screen.equals("Product")) {
String product = data.getQueryParameter("product");
// Open Product and give it product number as intent data
}
}
Update 2
Here's the relevant part of our Manifest.xml:
<activity
android:name="id.of.the.app.StartActivity"
android:configChanges="orientation|screenSize"
android:label="#string/app_title"
android:windowSoftInputMode="adjustPan|stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="scheme" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
Update 3
I'm still trying to understand if it's is possible to avoid a change to the manifest and resubmit the app. With the AndroidManifest you have published, have you tried to change just the rel-alternate tag to include a host (event if it's not included inside the manifest)? For example have you tried with android-app://id.of.the.app/scheme/fakehost/?screen=Product&product=123456 where fakehost is a string? I guess that the syntax of the tag must be android-app://{package_name}/{scheme}/{host_path}so it's neccessary to have an host in the web site (but probably not on the app).
Update 2
After you published the Manifest, I guess you're missing the mandatory 'host' in the data tag of your Intent-Filter.
Get this as reference:
<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="myapp" android:host="link"/>
<data android:scheme="myapp" android:host="link/"/>
</intent-filter>
and the meta in html should be (android-app://package-name/scheme/host)
<html>
<head>
<link rel="alternate"
href="android-app://it.test.testdeeplink/myapp/link/?p1=1&p2=2" />
...
</head>
You probably need to update your app, since your Manifest will have to be fixed.
First, thanks for all clarifications. I guess there is some confusion about deep link (the feature you're implementing) and Chrome Intent (the link that you provided as comment). So, I decided to implement a small project that you can download by my dropbox folder. The project is very simple and has a single activity that prints a line for every parameter received by Intent data (of course if you launch the app by the app launcher you won't see anything). The Activity supports two intent-filter schemas (my-android-app and http), and at the end of MainActivity.java you can find (as comment)
A line to test deep linking against adb and the first schema
A line to test deep linking against adb and the second schema
A simple html page to test the deep link using a browser - the last two href are Intent properly managed by Chrome.
Since I don't have access to your code, and I cannot see if there is any issue, I guess this is the best way to help you and to get my answer accepted :)
App indexing with query params in the Uri works fine for me. Please check if you followed all steps correctly:
Declare the scheme for the id.of.the.app.StartActivity in the 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="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="my_custom_scheme"/>
</intent-filter>
Parse deeplink
Let's assume we have following deeplink my_custom_scheme://test_authority/product_screen/?product=123456&test_param=0000&utm_source=google&utm_medium=organic&utm_campaign=appindexing
public void parseDeeplikUrl(Uri uri) {
if (uri == null) {
// fallback: open home screen
}
String autority = uri.getAuthority();
String path = uri.getPath();
String query = uri.getQuery();
// authority = "test_authority"
// path = "products_screen"
// query = "product=123456&test_param=0000&utm_source=google&utm_medium=organic&utm_campaign=appindexing"
}
Test app indexing from command line:
adb shell 'am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "my_custom_scheme://test_authority/product_screen/?product=123456&test_param=0000&utm_source=google&utm_medium=organic&utm_campaign=appindexing" -e android.intent.extra.REFERRER_NAME android-app://com.google.appcrawler/https/www.google.com id.of.the.app'
Using this adb command we simulate GoogleBot call.
Go to "Fetch as Google" in Search console and check if GoogleBot works fine too and renders correct application screen.
android-app://id.of.the.app/my_custom_scheme/test_authority/product_screen/?product=123456&test_param=0000&utm_source=google&utm_medium=organic&utm_campaign=appindexing
P.S.: Sometimes GoogleBot isn't rendering screens correctly. I got few empty screens with correct the deeplinks. In that case try to execute the same deeplinks again. It worked for me.
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):
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.
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>