Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Nextcloud Android Common Library
*
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: MIT
*/

package com.nextcloud.android.common.core.utils.ecosystem

import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import androidx.core.net.toUri

/**
* Helper class for opening Nextcloud apps if present
* or falling back to opening the app store
* in case the app is not yet installed on the device.
*/
object LinkHelper {
/**
* Open app store page of specified app or search for specified string. Will attempt to open browser when no app
* store is available.
*
* @param string packageName or url-encoded search string
* @param search false -> show app corresponding to packageName; true -> open search for string
*/
fun openAppStore(
string: String,
search: Boolean = false,
context: Context
) {
var suffix = (if (search) "search?q=" else "details?id=") + string
val intent = Intent(Intent.ACTION_VIEW, "market://$suffix".toUri())
try {
context.startActivity(intent)
} catch (_: ActivityNotFoundException) {
// all is lost: open Google play store web page for app
if (!search) {
suffix = "apps/$suffix"
}
intent.setData("https://play.google.com/store/$suffix".toUri())
context.startActivity(intent)
}
}
}
Loading
Loading