openUri: handle scheme-less urls

This commit is contained in:
Andrew Dolgov 2016-02-05 19:18:32 +03:00
parent 895e87c2a3
commit 48d2b51a1a

View File

@ -319,10 +319,20 @@ public class CommonActivity extends ActionBarActivity implements SharedPreferenc
}
// uses chrome custom tabs when available
public void openUri(final Uri uri) {
public void openUri(Uri uri) {
boolean enableCustomTabs = m_prefs.getBoolean("enable_custom_tabs", true);
final boolean askEveryTime = m_prefs.getBoolean("custom_tabs_ask_always", true);
if (uri.getScheme() == null) {
try {
uri = Uri.parse("https:" + uri.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
final Uri finalUri = uri;
if (enableCustomTabs && m_customTabClient != null) {
if (askEveryTime) {
@ -345,7 +355,7 @@ public class CommonActivity extends ActionBarActivity implements SharedPreferenc
editor.apply();
}
openUriWithCustomTab(uri);
openUriWithCustomTab(finalUri);
}
})
@ -361,7 +371,7 @@ public class CommonActivity extends ActionBarActivity implements SharedPreferenc
editor.apply();
}
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
Intent intent = new Intent(Intent.ACTION_VIEW, finalUri);
try {
startActivity(intent);