Fix intent to open ecosystem apps

Signed-off-by: ZetaTom <70907959+ZetaTom@users.noreply.github.com>
This commit is contained in:
ZetaTom 2023-06-30 10:00:41 +02:00 committed by Andy Scherzinger
parent b978e03f9f
commit f1c76614c2
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
2 changed files with 11 additions and 12 deletions

View file

@ -351,12 +351,10 @@ public abstract class DrawerActivity extends ToolbarActivity
ecosystemApps.setVisibility(View.GONE);
} else {
ecosystemApps.findViewById(R.id.drawer_ecosystem_notes).setOnClickListener(v -> {
openAppOrStore("it.niedermann.owncloud.notes",
"it.niedermann.owncloud.notes.main.MainActivity");
openAppOrStore("it.niedermann.owncloud.notes");
});
ecosystemApps.findViewById(R.id.drawer_ecosystem_talk).setOnClickListener(v -> {
openAppOrStore("com.nextcloud.talk2",
"com.nextcloud.talk.activities.MainActivity");
openAppOrStore("com.nextcloud.talk2");
});
ecosystemApps.findViewById(R.id.drawer_ecosystem_more).setOnClickListener(v -> {
openAppStore("Nextcloud", true);
@ -368,16 +366,15 @@ public abstract class DrawerActivity extends ToolbarActivity
* Open specified app and, if not installed redirect to corresponding download.
*
* @param packageName of app to be opened
* @param className of app for intent to be called
*/
private void openAppOrStore(String packageName, String className) {
try {
// attempt to open app directly
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName(packageName, className);
private void openAppOrStore(String packageName) {
Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
if (intent != null) {
// app installed - open directly
intent.putExtra(FileDisplayActivity.KEY_ACTIVE_USER, getUser().get().hashCode());
startActivity(intent);
} catch (android.content.ActivityNotFoundException activityNotFoundException) {
// attempt to open market (Google Play Store, F-Droid, etc.)
} else {
// app not found - open market (Google Play Store, F-Droid, etc.)
openAppStore(packageName, false);
}
}

View file

@ -191,6 +191,7 @@ public class FileDisplayActivity extends FileActivity
public static final String KEY_FILE_ID = "KEY_FILE_ID";
public static final String KEY_FILE_PATH = "KEY_FILE_PATH";
public static final String KEY_ACCOUNT = "KEY_ACCOUNT";
public static final String KEY_ACTIVE_USER = "KEY_ACTIVE_USER";
private static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
@ -2491,6 +2492,7 @@ public class FileDisplayActivity extends FileActivity
String userName = intent.getStringExtra(KEY_ACCOUNT);
String fileId = intent.getStringExtra(KEY_FILE_ID);
String filePath = intent.getStringExtra(KEY_FILE_PATH);
String activeUser = intent.getStringExtra(KEY_ACTIVE_USER);
if (userName == null && fileId == null && intent.getData() != null) {
openDeepLink(intent.getData());