Guest User

Untitled

a guest
Jul 3rd, 2025
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 2.12 KB | Source Code | 0 0
  1. app/src/flavorA/res/xml/shortcuts.xml
  2.  
  3.     1 <?xml version="1.0" encoding="utf-8"?>
  4.     2 <shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
  5.     3     <capability android:name="actions.intent.WATCH_CONTENT">
  6.     4         <intent
  7.    5             android:action="android.intent.action.VIEW"
  8.    6             android:targetPackage="com.awesome.app"
  9.    7             android:targetClass="com.something.else.MainActivity">
  10.     8             <parameter
  11.    9                 android:name="content.name"
  12.   10                 android:key="feature"
  13.   11                 android:mimeType="text/*" />
  14.    12         </intent>
  15.    13     </capability>
  16.    14 </shortcuts>
  17.  
  18. app/src/flavorA/AndroidManifest.xml (inside the main launcher `<activity>` tag):
  19.     1 <activity
  20.    2     android:name=".MainActivity"
  21.    3     android:exported="true"
  22.    4     ...>
  23.     5     <intent-filter>
  24.     6         <action android:name="android.intent.action.MAIN" />
  25.     7         <category android:name="android.intent.category.LAUNCHER" />
  26.     8     </intent-filter>
  27.     9
  28.    10     <meta-data
  29.   11         android:name="android.app.shortcuts"
  30.   12         android:resource="@xml/shortcuts" />
  31.    13 </activity>
  32.  
  33. `MainActivity.kt` (relevant parts):
  34.  
  35.     1 override fun onCreate(savedInstanceState: Bundle?) {
  36.     2     // ...
  37.     3     handleIntent(intent)
  38.     4 }
  39.     5
  40.     6 override fun onNewIntent(intent: Intent?) {
  41.     7     super.onNewIntent(intent)
  42.     8     handleIntent(intent)
  43.     9 }
  44.    10
  45.    11 private fun handleIntent(intent: Intent?) {
  46.    12     // This check is for flavor-specific logic
  47.    13     if (BuildConfig.FLAVOR == "flavorA") {
  48.    14         intent?.let {
  49.    15             if (it.action == Intent.ACTION_VIEW) {
  50.    16                 val channelName = it.getStringExtra("feature")
  51.    17                 if (channelName != null) {
  52.    18                     Log.d("AppActions", "Received channel: $channelName")
  53.    19                     Toast.makeText(this, "Channel: $channelName", Toast.LENGTH_LONG).show()
  54.    20                 }
  55.    21             }
  56.    22         }
  57.    23     }
  58.    24 }
Tags: xml Kotlin
Advertisement
Add Comment
Please, Sign In to add comment