Ensure intent are resolved when opening link

This commit is contained in:
tonymanou 2018-08-05 20:33:07 +02:00 committed by John Wu
parent d764c20c08
commit 9e72317302
2 changed files with 12 additions and 4 deletions

View File

@ -1,6 +1,5 @@
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
@ -12,6 +11,7 @@ import android.view.View;
import com.topjohnwu.magisk.asyncs.MarkDownWindow; import com.topjohnwu.magisk.asyncs.MarkDownWindow;
import com.topjohnwu.magisk.components.AboutCardRow; import com.topjohnwu.magisk.components.AboutCardRow;
import com.topjohnwu.magisk.components.BaseActivity; import com.topjohnwu.magisk.components.BaseActivity;
import com.topjohnwu.magisk.utils.Utils;
import java.util.Locale; import java.util.Locale;
@ -65,13 +65,13 @@ public class AboutActivity extends BaseActivity {
} }
appSourceCode.removeSummary(); appSourceCode.removeSummary();
appSourceCode.setOnClickListener(view -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Const.Url.SOURCE_CODE_URL)))); appSourceCode.setOnClickListener(view -> Utils.openLink(this, Uri.parse(Const.Url.SOURCE_CODE_URL)));
supportThread.removeSummary(); supportThread.removeSummary();
supportThread.setOnClickListener(view -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Const.Url.XDA_THREAD)))); supportThread.setOnClickListener(view -> Utils.openLink(this, Uri.parse(Const.Url.XDA_THREAD)));
donation.removeSummary(); donation.removeSummary();
donation.setOnClickListener(view -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Const.Url.DONATION_URL)))); donation.setOnClickListener(view -> Utils.openLink(this, Uri.parse(Const.Url.DONATION_URL)));
setFloating(); setFloating();
} }

View File

@ -4,6 +4,7 @@ import android.app.job.JobInfo;
import android.app.job.JobScheduler; import android.app.job.JobScheduler;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
@ -88,6 +89,13 @@ public class Utils {
} }
} }
public static void openLink(Context context, Uri link) {
Intent intent = new Intent(Intent.ACTION_VIEW, link);
if (intent.resolveActivity(context.getPackageManager()) != null) {
context.startActivity(intent);
}
}
public static void toast(CharSequence msg, int duration) { public static void toast(CharSequence msg, int duration) {
Data.mainHandler.post(() -> Toast.makeText(Data.MM(), msg, duration).show()); Data.mainHandler.post(() -> Toast.makeText(Data.MM(), msg, duration).show());
} }