Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static android shortcuts for multiple flavors?

Tags:

Is it possible to define static shortcuts for multiple flavors without duplicating the shortcuts.xml ? I have two flavors:

  • main (package: com.test)
  • free (package: com.test.free)

The shortcuts.xml looks like this:

<shortcuts xmlns:android="http://schemas.android.com/apk/res/android"> <shortcut     android:enabled="true"     android:icon="@drawable/ic_shortcut_add_photo"     android:shortcutId="new_photo"     android:shortcutLongLabel="@string/new_photo"     android:shortcutShortLabel="@string/new_photo">      <intent         android:action="android.intent.action.VIEW"         android:targetClass="com.test.MainActivity"         android:targetPackage="com.test"/> </shortcut> 

The problem is that the package name in the intent can not refer to a string resource and must be hardcoded in the xml.

To also provide the shortcuts for the free flavor i have to copy the shortcuts.xml and change the targetPackage to com.test.free which is a bad solution.

like image 769
André Roß Avatar asked Nov 01 '16 13:11

André Roß


People also ask

What are dynamic shortcuts?

Dynamic shortcuts are used for actions in apps that are context-sensitive. Context-sensitive shortcuts are tailored to the actions users perform in an app. For instance, if you build a game that allows the user to start from their current level on launch, you should update the shortcut frequently.

What is reset ShortcutManager rate limiting?

However, rate limiting is reset during certain events, so even background apps can call ShortcutManager methods until the rate limit is reached again. These events include the following: An app comes to the foreground. The system locale changes. The user performs the inline reply action on a notification.

What is shortcuts XML?

Static shortcuts xml to extend the functionality of the capability. Static shortcuts are ingested by Assistant when you upload a release to Google Play Console. Since static shortcuts can only be created and updated by creating new releases, they are most useful to highlight common activities and content in your app.


Video Answer


1 Answers

I created a plugin which make it possible to use manifestPlaceholders in resources and is usable with version 3.0.0 of the android gradle plugin

https://github.com/timfreiheit/ResourcePlaceholdersPlugin

src/main/res/shortcuts.xml:

<shortcuts xmlns:android="http://schemas.android.com/apk/res/android"> <shortcut     android:enabled="true"     android:icon="@drawable/ic_shortcut_add_photo"     android:shortcutId="new_photo"     android:shortcutLongLabel="@string/new_photo"     android:shortcutShortLabel="@string/new_photo">      <intent         android:action="android.intent.action.VIEW"         android:targetClass="com.test.MainActivity"         android:targetPackage="${applicationId}"/> </shortcut> 
like image 190
Tim Freiheit Avatar answered Sep 20 '22 08:09

Tim Freiheit