<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!
Related
I would like to add a "Guided breathing" activity type, supported by the REST Api under id 122:
https://developers.google.com/fit/rest/v1/reference/activity-types
However, it is not available in the FitnessActivites class, despite the fact that most (all?) other are:
https://developers.google.com/android/reference/com/google/android/gms/fitness/FitnessActivities
Is there a way to add this particular activity type through the Google Fit SDK? I know I can just set a different name with a Session.Builder.setName method, but that wouldn't be sufficiently localised.
This will be available in the next SDK release.
Activity types are just String literals, so I believe you could just use "guided_breathing" in the interim.
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.
Background
Starting from Android O, it's possible to create pinned shortcuts, which (on supported launchers) show a dialog to confirm the creation of them:
ShortcutInfoCompat pinShortcutInfo = new ShortcutInfoCompat.Builder(context, uniqueShortcutId)
.setShortLabel(label)
.setIntent(shortcutIntent)
.setLongLabel(label)
.setIcon(IconCompat.createWithBitmap(bitmap))
.build();
ShortcutManagerCompat.requestPinShortcut(this, pinShortcutInfo , null);
Docs:
https://developer.android.com/reference/android/content/pm/ShortcutManager.html
https://developer.android.com/guide/topics/ui/shortcuts.html
The problem
Sometimes, the pinned shortcut is not relevant anymore. For example, it points to something that doesn't exist anymore.
In this case, I want to be able to remove it.
What I've tried
I thought this is possible by the next code, but it doesn't, because it is probably about dynamic shortcuts, which is something else :
ShortcutManager shortcutManager = (ShortcutManager) getSystemService(SHORTCUT_SERVICE);
final List<ShortcutInfo> pinnedShortcuts = shortcutManager.getPinnedShortcuts();
final ArrayList<String> shortcutIdsToRemove = new ArrayList<>();
for (ShortcutInfo pinnedShortcut : pinnedShortcuts) {
final Intent pinnedShortcutIntent = pinnedShortcut.getIntent();
shortcutIdsToRemove.add(pinnedShortcut.getId());
}
shortcutManager.removeDynamicShortcuts(shortcutIdsToRemove);
// this also doesn't work : shortcutManager.disableShortcuts(shortcutIdsToRemove);
The question
How can I remove pinned shortcuts? Is it even possible?
Update: seems it isn't possible, as Google mentioned here.
So far, this API seems very restricting to me, as it has so many disadvantages:
The created icon image cannot be created from a resource ID.
On the launcher, the created icon has a tiny icon of the app that created it.
The icon cannot be removed via the API (only disabled), so if you created one that points to another app, and this app was removed, you won't be able to remove it.
The creation cannot be in the background, as it requires a confirmation dialog. It also cannot be created in a batch. Only one after another.
All pinned shortcuts your app has created will be removed if your app was removed.
So, my question now is:
Is there any way to create and remove a shortcut using the previous API, using an adb command, with root if needed ?
Is it possible to remove specific pinned shortcuts using adb command , with root if needed?
disableShortcuts() is the best you can do. It will show the user a custom error message when they try to select the disabled shortcut.
From the official documentation:
Shortcut limitations
Although you can publish up to five shortcuts (static and dynamic shortcuts combined) at a time for your app, most launchers can only display four.
However, there is no limit to the number of pinned shortcuts to your app that users can create. Even though your app cannot remove pinned shortcuts, it can still disable them.
Another section:
Because your app and its users can pin shortcuts to the device's launcher, it's possible that these pinned shortcuts could direct users to actions within your app that are out of date or no longer exist. To manage this situation, you can disable the shortcuts that you don't want users to select by calling disableShortcuts(), which removes the specified shortcuts from the static and dynamic shortcuts list and disables any pinned copies of these shortcuts. You can also use an overloaded version of this method, which accepts a CharSequence as a custom error message. That error message then appears when users attempt to launch any disabled shortcut.
Note: If you remove some of your app's static shortcuts when you update your app, the system disables these shortcuts automatically.
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.
I am quite new to Android
I studied how to use category (in the intent-filter). And I know category is used for grouping the activities. But didn't understand what is the real use of - category.
Can any help me in this regard - siting the practical use of category.
Thanks
The category gives additional information about the action to execute. For example, CATEGORY_LAUNCHER means it should appear in the Launcher as a top-level application, while CATEGORY_ALTERNATIVE means it should be included in a list of alternative actions the user can perform on a piece of data.
Here is a full list of categories with a short description