Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app/src/flavorA/res/xml/shortcuts.xml
- 1 <?xml version="1.0" encoding="utf-8"?>
- 2 <shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
- 3 <capability android:name="actions.intent.WATCH_CONTENT">
- 4 <intent
- 5 android:action="android.intent.action.VIEW"
- 6 android:targetPackage="com.awesome.app"
- 7 android:targetClass="com.something.else.MainActivity">
- 8 <parameter
- 9 android:name="content.name"
- 10 android:key="feature"
- 11 android:mimeType="text/*" />
- 12 </intent>
- 13 </capability>
- 14 </shortcuts>
- app/src/flavorA/AndroidManifest.xml (inside the main launcher `<activity>` tag):
- 1 <activity
- 2 android:name=".MainActivity"
- 3 android:exported="true"
- 4 ...>
- 5 <intent-filter>
- 6 <action android:name="android.intent.action.MAIN" />
- 7 <category android:name="android.intent.category.LAUNCHER" />
- 8 </intent-filter>
- 9
- 10 <meta-data
- 11 android:name="android.app.shortcuts"
- 12 android:resource="@xml/shortcuts" />
- 13 </activity>
- `MainActivity.kt` (relevant parts):
- 1 override fun onCreate(savedInstanceState: Bundle?) {
- 2 // ...
- 3 handleIntent(intent)
- 4 }
- 5
- 6 override fun onNewIntent(intent: Intent?) {
- 7 super.onNewIntent(intent)
- 8 handleIntent(intent)
- 9 }
- 10
- 11 private fun handleIntent(intent: Intent?) {
- 12 // This check is for flavor-specific logic
- 13 if (BuildConfig.FLAVOR == "flavorA") {
- 14 intent?.let {
- 15 if (it.action == Intent.ACTION_VIEW) {
- 16 val channelName = it.getStringExtra("feature")
- 17 if (channelName != null) {
- 18 Log.d("AppActions", "Received channel: $channelName")
- 19 Toast.makeText(this, "Channel: $channelName", Toast.LENGTH_LONG).show()
- 20 }
- 21 }
- 22 }
- 23 }
- 24 }
Advertisement
Add Comment
Please, Sign In to add comment