Skip to content

Commit 6f59e6a

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 6f59e6a

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

  • core/src/main/java/com/nextcloud/android/common/core/utils/ecosystem
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
}

0 commit comments

Comments
 (0)