Android app-action with custom query pattern - android

I have an android app that using com.google.android.gms.actions.SEARCH_ACTION
to search a phrase on my app using search for PHRASE on APP_NAME, but now I want use custom voice command like APP_NAME PHRASE to open my app and pass that phrase using google assistant.
So is it possible to implement this feature?
I have tried with https://github.com/actions-on-google/appactions-fitness-kotlin to get deep idea about actually how action intent works and found that it may be possible using deep linking.
Here in this example in actions.xml file one action actions.intent.GET_EXERCISE_OBSERVATION implemented as you can see below code.
<action intentName="actions.intent.GET_EXERCISE_OBSERVATION">
<fulfillment
fulfillmentMode="actions.fulfillment.SLICE"
urlTemplate="content://com.devrel.android.fitactions.FitSliceProvider/stats{?exerciseType}">
<parameter-mapping
entityMatchRequired="true"
intentParameter="exerciseObservation.aboutExercise.name"
required="true"
urlParameter="exerciseType" />
</fulfillment>
<fulfillment
fulfillmentMode="actions.fulfillment.DEEPLINK"
urlTemplate="https://fit-actions.firebaseapp.com/stats" />
<parameter name="exerciseObservation.aboutExercise.name">
<entity-set-reference entitySetId="ExerciseEntitySet" />
</parameter>
</action>
<!-- Defines an entity set with our supported entities -->
<entity-set entitySetId="ExerciseEntitySet">
<entity
name="#string/activity_running"
alternateName="#array/runningSynonyms"
identifier="RUNNING" />
<entity
name="#string/activity_walking"
alternateName="#array/walkingSynonyms"
identifier="WALKING" />
<entity
name="#string/activity_cycling"
alternateName="#array/cyclingSynonyms"
identifier="CYCLING" />
</entity-set>
But now I have some questions regarding this code.
How urlTemplate content://com.devrel.android.fitactions.FitSliceProvider/stats{?exerciseType} for actions.fulfillment.SLICE is generated?
Can exerciseObservation.aboutExercise.name have any custom value rather then defined in entity-set ?
How urlTemplate https://fit-actions.firebaseapp.com/stats for actions.fulfillment.DEEPLINK is generated?
After implementing this I think actions.intent.OPEN_APP_FEATURE will be helpful with the help of DEEPLINK fulfillment.
So is it possible to implement this using actions.intent.OPEN_APP_FEATURE"?

How urlTemplate content://com.devrel.android.fitactions.FitSliceProvider/stats{?exerciseType}
for actions.fulfillment.SLICE is generated?
The urlTemplate value (whether fulfilling via slice or deep link) is fully up to you to define. In the case of a deep link, this is the URL the system will call to open up your app. In the case of a Slice, this is the contentUri the system will call to render the Slice. The parameters inside the {} will be expanded with values at runtime. To get a better understanding of how that works, see the docs here and here or the Google I/O 2019 session.
Can exerciseObservation.aboutExercise.name have any custom value rather then defined in entity-set ?
I'm not exactly sure what you mean here but let me try and give more detail. The param name of exerciseObservation.aboutExercise.name is set for each Assistant Intent can cannot be changed. These values are listed in the documentation (example). The actual values of the parameters (that are populated by the user's query at runtime) are dynamic and will change based on the user's query and the Assistant Intent. For each Assistant Intent, you can refer to the docs to see what the possible values can be. In some cases they are from a set list of values (like for GET_EXERCISE_OBSERVATION), for others it could be a free form value based on the user's input, and for others still you can optionally extend the values using inline inventory (this is what you use <entity-set> for in your example).
How urlTemplate https://fit-actions.firebaseapp.com/stats for
actions.fulfillment.DEEPLINK is generated?
As per #1, the value of urlTemplate is totally up to you to configure. It can be any Android Intent URI. The system will call this Uri to start up your app/Activity.
After implementing this I think
actions.intent.OPEN_APP_FEATURE will be helpful with the
help of DEEPLINK fulfillment.
So is it possible to implement this using
actions.intent.OPEN_APP_FEATURE"?
OPEN_APP_FEATURE is just another Assistant Intent that allows a generic call into a feature of your app. The docs were recently updated with some example queries. Eg.
Open Youtube history
This example will open the app named "YouTube" and pass the feature name "history" to the app to handle.
Open Example App Example feature
This example will open the app named "Example App" and pass the feature name "Example feature" to the app to handle.

Related

Intent setAction ACTION_SNOOZE retired?

hmm, even the android developer page:
Developers
shows this line in the example for notification 'snooze' code:
snoozeIntent.setAction(ACTION_SNOOZE);
but when I try to use it in my Android Studio (3.6.1), it doesn't accept it (or offer it when asking for list of ACTION_ suggestions).
Google is not my friend here, any idea what's wrong on my side?
I think in this case you do not use a predefined 'Intent.ACTION_...'. Instead you create your own constant, being a String, and retrieve this when accepting the intent with 'getAction()'.
For the official link:
https://developer.android.com/reference/android/content/Intent#setAction(java.lang.String)
Although it does not specify such behavior explicitly, it is okay to do this. Unfortunate the guide about 'Notifications' did not expanded on this subject. However, you can see a similar behavior being done with the CHANNEL_ID oa.
As an extra:
If you define your own actions, be sure to include your app's package name as a prefix, as shown in the following example:
Link: https://developer.android.com/guide/components/intents-filters#Building

Android Navigation Deep Link - Ignore Query

I'm attempting to add a deep-link for a URL that has the following format:
<deepLink
android:id="#+id/deep_link"
android:autoVerify="true"
app:uri="my.example.com/articles/{slug}" />
This causes the slug argument passed to my destination to also include the query if it exists. For example, the URL my.example.com/articles/recent-article?utm=1 results in the slug argument being recent-article?utm=1.
I've tried using the following pattern format in an attempt to ignore the query, but URLs no longer match correctly.
<deepLink
android:id="#+id/deep_link"
android:autoVerify="true"
app:uri="my.example.com/articles/{slug}?*.*" />
Is there a way to effectively ignore the query?
Assuming you're using the latest Navigation 2.2.0-rc04 (or one of the other Navigation 2.2 releases that adds support for query parameters), it sounds like you're hitting this issue where deeplinks without query parameters don't ignore query parameters.
The workaround mentioned in the bug is to include a dummy parameter:
<deepLink
android:id="#+id/deep_link"
android:autoVerify="true"
app:uri="my.example.com/articles/{slug}?dummy={dummy} />

Deep-linking with Navigation Uri issue when using strings.xml

I am checking below google sample code for test Deep-linking with Navigation.
Navigation with Deep linking Basic Sample
It works well. But in navigation.xml file I don't want to add uri directly , I want to use strings.xml file for same.
Not this :
<deepLink app:uri="www.example.com/user/{userName}" />
but , Want to do like this ,
<deepLink app:uri="#string/profile_url" />
the reason is that, if there is any changes in URL then I just have to go in strings.xml file and replace relative things.
Let me know if you have better idea about it or any better optimized solution.

What "android.shortcut.conversation" means in shortcuts.xml?

<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="compose"
android:enabled="true"
android:icon="#drawable/compose_icon"
android:shortcutShortLabel="#string/compose_shortcut_short_label1"
android:shortcutLongLabel="#string/compose_shortcut_long_label1"
android:shortcutDisabledMessage="#string/compose_disabled_message1">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.example.myapplication"
android:targetClass="com.example.myapplication.ComposeActivity" />
<!-- This -->
<categories android:name="android.shortcut.conversation" />
</shortcut>
</shortcuts>
What other value is available? Do I need to include this category and what if I delete it?
I did not find this in the official documentation - https://developer.android.com/guide/topics/ui/shortcuts.html
categories tag is used to provide a grouping for the types of actions that your app's shortcuts perform. One of the available groups is android.shortcut.conversation, and this is used if you want to add a shortcut to conversation of chat application. For example, a shortcut to the most recent chat head. You would only need to add this in your shortcuts.xml, when you want to provide the said shortcut. Otherwise you don't need it. You can delete it.
For API level 26 or lower this is the only value that is avaliable. But for higher versions there are multiple.
For a list of supported shortcut categories you can see this page.
At this moment only one type supported category is android.shortcut.conversation. You can find it in ShortcutInfo
/**
* Shortcut category for messaging related actions, such as chat.
*/
public static final String SHORTCUT_CATEGORY_CONVERSATION = "android.shortcut.conversation";
Also in
/**
* Sets categories for a shortcut. Launcher apps may use this information to
* categorize shortcuts.
*
* #see #SHORTCUT_CATEGORY_CONVERSATION
* #see ShortcutInfo#getCategories()
*/
#NonNull
public Builder setCategories(Set<String> categories) {
mCategories = categories;
return this;
}
Shortcut category for messaging related actions, such as chat.
TL;DR in 2022: Seems like the "category" inner element became a forgotten feature of Android Shortcuts, and there only ended up being that one pre-defined "Conversation" category. Capabilities, on the other hand, are very well fleshed out and fill those boots quite well! Check out the link below for what capabilities can help you unlock!
In more detail as of 2022, Android API Level 25 introduced the ability to define shortcuts, letting you provide the user with a static set of shortcuts into your app for common actions like creating a new email as well as a dynamic set of shortcuts like sending a message to a recent contact.
It seems that the "category" inner element was intended to group certain similar shortcuts together. Unfortunately it seems the idea was abandoned likely due to the limited number of shortcuts that could appear in the small popup menu. These days the most I've seen is 5, and it can definitely vary based on your device. As a result of the limited space, it seems the only category that has been defined, even today with API level 32 available, is the "Conversation" category.
Due to its limited development, I find it best 99% of the time to leave off the "category" inner element in favor of the "capability" inner element which has quite the long list of pre-defined options that correspond to Built-In Intents (which can add amazing Google Assistant actions to your app)!
Here's the list of all of them!

Change the title of Paypal PaymentActivity class

I included paypal sdk in the app and set the product name and price as shown in the attached image.
Is it possible to change the title of the paypal PaymentActivity class . ?
I used the entire code for paypal from this link
.Please suggest whether we could change the title to any text ,(I want to change the text that is marked in Red Circle)?
Jeff here from the PayPal Mobile SDK team.
The PayPal Android SDK doesn't support modifying any of the SDK activities. We don't plan to allow the ability to modify titles, as this would be an inconsistent user experience. However, we're open to feedback from users, so please feel free to file issues in GitHub if you have feature requests!
Couple observations, apparently:
The activity of off which you have put screenshot is PaymentMethodActivity (according to Hierarchy Viewer)
PayPal SDK uses ABS
According to the sample app provided in PayPal SDK page, onBuyPressed() launches PaymentActivity with startActivityForResult():
Now, according to SDK references, PaymentActivity does not provide any API for setting custom title. The page lists setTitle() as a part of "Methods inherited from class android.app.Activity", but does not give any details on how to extend PaymentActivity so that one could leverage those APIs.
So, currently, there is no way to use a custom title.
I personally would not bother to change the title on that screen as it clearly depicts itself as a PayPal screen (as one would see their homepage on a browser), but if you really want a custom title, you may need to file a new issue on their GitHub page.
Your AndroidManifest.xml file should have an entry for the PaymentActivity that looks like this:
<activity android:name="com.paypal.android.sdk.payments.PaymentActivity" />
All you should have to do is add the label attribute to that to change the title:
<activity android:name="com.paypal.android.sdk.payments.PaymentActivity" android:label="#string/some_title" />
For other potentially useful attributes, refer to the activity tag documentation.
Note: I'm assuming here that the PayPal SDK will allow you to override the title. That is, I would expect it to only set a default title if none is given explicitly.
Edit: Unfortunately, the assumption above has proven to be incorrect. Diving a little deeper, it turns out every activity in the PayPal SDK always sets its title in the onCreate() method. That's actually a little surprising, because that means that PayPal isn't leveraging Android's built-in support for localisation and resources. Although I suppose it does allow them to offer developers the SDK as a jar, which doesn't support bundling Android resources.
In any case, since the various activities haven't been declared final, you could simply try to extend them and set the title after the super has done its work:
public class TitlePaymentMethodActivity extends PaymentMethodActivity {
#Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("Custom Title")
// or:
setTitle(R.string.custom_title);
}
}
After that, you'll have to change the manifest to point to your TitlePaymentMethodActivity, in stead of directly to the activity in the SDK. Do note that this approach may break at any point, if PayPal decides to finalize the activity classes. With that in mind, I suggest you follow #shoe rat's recommendation and file a request with PayPal for 'official' support.

Categories

Resources