Skip to content

Commit d9e7ece

Browse files
feat: Add link helper to open App Store for Nextcloud apps
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
1 parent aa0d20e commit d9e7ece

File tree

2 files changed

+1111
-0
lines changed

2 files changed

+1111
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Nextcloud Android Common Library
3+
*
4+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
package com.nextcloud.android.common.core.utils.ecosystem
9+
10+
import android.content.ActivityNotFoundException
11+
import android.content.Context
12+
import android.content.Intent
13+
import androidx.core.net.toUri
14+
15+
/**
16+
* Helper class for opening Nextcloud apps if present
17+
* or falling back to opening the app store
18+
* in case the app is not yet installed on the device.
19+
*/
20+
object LinkHelper {
21+
/**
22+
* Open app store page of specified app or search for specified string. Will attempt to open browser when no app
23+
* store is available.
24+
*
25+
* @param string packageName or url-encoded search string
26+
* @param search false -> show app corresponding to packageName; true -> open search for string
27+
*/
28+
fun openAppStore(
29+
string: String,
30+
search: Boolean = false,
31+
context: Context
32+
) {
33+
var suffix = (if (search) "search?q=" else "details?id=") + string
34+
val intent = Intent(Intent.ACTION_VIEW, "market://$suffix".toUri())
35+
try {
36+
context.startActivity(intent)
37+
} catch (_: ActivityNotFoundException) {
38+
// all is lost: open Google play store web page for app
39+
if (!search) {
40+
suffix = "apps/$suffix"
41+
}
42+
intent.setData("https://play.google.com/store/$suffix".toUri())
43+
context.startActivity(intent)
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)