File tree Expand file tree Collapse file tree
core/src/main/java/com/nextcloud/android/common/core/utils/ecosystem Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ /* *
23+ * Open app store page of specified app or search for specified string. Will attempt to open browser when no app
24+ * store is available.
25+ *
26+ * @param string packageName or url-encoded search string
27+ * @param search false -> show app corresponding to packageName; true -> open search for string
28+ */
29+ fun openAppStore (string : String , search : Boolean = false, context : Context ) {
30+ var suffix = (if (search) " search?q=" else " details?id=" ) + string
31+ val intent = Intent (Intent .ACTION_VIEW , " market://$suffix " .toUri())
32+ try {
33+ context.startActivity(intent)
34+ } catch (_: ActivityNotFoundException ) {
35+ // all is lost: open Google play store web page for app
36+ if (! search) {
37+ suffix = " apps/$suffix "
38+ }
39+ intent.setData(" https://play.google.com/store/$suffix " .toUri())
40+ context.startActivity(intent)
41+ }
42+ }
43+ }
You can’t perform that action at this time.
0 commit comments