Force intent to default browser when opening things in browser
fixes #881
This commit is contained in:
parent
9f4575f349
commit
e174a7efd7
1 changed files with 24 additions and 11 deletions
|
@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
|
|||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.ClipData;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.ColorStateList;
|
||||
|
@ -124,18 +125,30 @@ public class UiUtils{
|
|||
private UiUtils(){}
|
||||
|
||||
public static void launchWebBrowser(Context context, String url){
|
||||
try{
|
||||
Intent intent;
|
||||
if(GlobalUserPreferences.useCustomTabs){
|
||||
new CustomTabsIntent.Builder()
|
||||
intent=new CustomTabsIntent.Builder()
|
||||
.setShowTitle(true)
|
||||
.build()
|
||||
.launchUrl(context, Uri.parse(url));
|
||||
.intent;
|
||||
}else{
|
||||
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
|
||||
intent=new Intent(Intent.ACTION_VIEW);
|
||||
}
|
||||
}catch(ActivityNotFoundException x){
|
||||
intent.setData(Uri.parse(url));
|
||||
ComponentName handler=intent.resolveActivity(context.getPackageManager());
|
||||
if(handler==null){
|
||||
Toast.makeText(context, R.string.no_app_to_handle_action, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if(handler.getPackageName().equals(context.getPackageName())){ // Oops. Let's prevent the app from opening itself.
|
||||
ComponentName browserActivity=new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com")).resolveActivity(context.getPackageManager());
|
||||
if(browserActivity==null){
|
||||
Toast.makeText(context, R.string.no_app_to_handle_action, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
intent.setComponent(browserActivity);
|
||||
}
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
public static String formatRelativeTimestamp(Context context, Instant instant){
|
||||
|
|
Loading…
Add table
Reference in a new issue