Merge pull request #3451 from ByteHamster/fix-no-browser-installed

Fixed crash if there is no browser installed
This commit is contained in:
H. Lehmann 2019-09-26 18:52:01 +02:00 committed by GitHub
commit 1e883758e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 33 additions and 70 deletions

View File

@ -15,6 +15,7 @@ import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import de.danoeh.antennapod.core.util.IntentUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import java.io.IOException; import java.io.IOException;
@ -57,8 +58,7 @@ public class AboutActivity extends AppCompatActivity {
@Override @Override
public boolean shouldOverrideUrlLoading(WebView view, String url) { public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("http")) { if (url.startsWith("http")) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); IntentUtils.openInBrowser(AboutActivity.this, url);
startActivity(browserIntent);
return true; return true;
} else { } else {
url = url.replace("file:///android_asset/", ""); url = url.replace("file:///android_asset/", "");

View File

@ -1,19 +1,16 @@
package de.danoeh.antennapod.activity; package de.danoeh.antennapod.activity;
import android.content.ActivityNotFoundException;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import de.danoeh.antennapod.CrashReportWriter; import de.danoeh.antennapod.CrashReportWriter;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.util.IntentUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import java.io.File; import java.io.File;
@ -45,13 +42,7 @@ public class BugReportActivity extends AppCompatActivity {
} }
findViewById(R.id.btn_open_bug_tracker).setOnClickListener(v -> { findViewById(R.id.btn_open_bug_tracker).setOnClickListener(v -> {
try { IntentUtils.openInBrowser(BugReportActivity.this, "https://github.com/AntennaPod/AntennaPod/issues");
Intent myIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://github.com/AntennaPod/AntennaPod/issues"));
startActivity(myIntent);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, R.string.pref_no_browser_found, Toast.LENGTH_LONG).show();
}
}); });
findViewById(R.id.btn_copy_log).setOnClickListener(v -> { findViewById(R.id.btn_copy_log).setOnClickListener(v -> {

View File

@ -452,8 +452,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
} }
break; break;
case R.id.visit_website_item: case R.id.visit_website_item:
Uri uri = Uri.parse(getWebsiteLinkWithFallback(media)); IntentUtils.openInBrowser(MediaplayerActivity.this, getWebsiteLinkWithFallback(media));
startActivity(new Intent(Intent.ACTION_VIEW, uri));
break; break;
case R.id.share_link_item: case R.id.share_link_item:
if (feedItem != null) { if (feedItem != null) {

View File

@ -15,6 +15,7 @@ import java.lang.ref.WeakReference;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.util.IntentUtils;
public class RatingDialog { public class RatingDialog {
@ -62,11 +63,7 @@ public class RatingDialog {
if (context == null) { if (context == null) {
return; return;
} }
final String appPackage = "de.danoeh.antennapod"; IntentUtils.openInBrowser(context, "https://play.google.com/store/apps/details?id=de.danoeh.antennapod");
final Uri uri = Uri.parse("https://play.google.com/store/apps/details?id=" + appPackage);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
saveRated(); saveRated();
} }

View File

@ -96,13 +96,7 @@ public class ItemDescriptionFragment extends Fragment {
if (Timeline.isTimecodeLink(url)) { if (Timeline.isTimecodeLink(url)) {
onTimecodeLinkSelected(url); onTimecodeLinkSelected(url);
} else { } else {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); IntentUtils.openInBrowser(getContext(), url);
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
return true;
}
} }
return true; return true;
} }
@ -159,11 +153,7 @@ public class ItemDescriptionFragment extends Fragment {
if (selectedURL != null) { if (selectedURL != null) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.open_in_browser_item: case R.id.open_in_browser_item:
Uri uri = Uri.parse(selectedURL); IntentUtils.openInBrowser(getContext(), selectedURL);
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
if(IntentUtils.isCallable(getActivity(), intent)) {
getActivity().startActivity(intent);
}
break; break;
case R.id.share_url_item: case R.id.share_url_item:
ShareUtils.shareLink(getActivity(), selectedURL); ShareUtils.shareLink(getActivity(), selectedURL);

View File

@ -210,10 +210,7 @@ public class ItemFragment extends Fragment implements OnSwipeGesture {
webvDescription.setWebViewClient(new WebViewClient() { webvDescription.setWebViewClient(new WebViewClient() {
@Override @Override
public boolean shouldOverrideUrlLoading(WebView view, String url) { public boolean shouldOverrideUrlLoading(WebView view, String url) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); IntentUtils.openInBrowser(getContext(), url);
if(IntentUtils.isCallable(getActivity(), intent)) {
startActivity(intent);
}
return true; return true;
} }
}); });
@ -484,11 +481,7 @@ public class ItemFragment extends Fragment implements OnSwipeGesture {
if (selectedURL != null) { if (selectedURL != null) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.open_in_browser_item: case R.id.open_in_browser_item:
Uri uri = Uri.parse(selectedURL); IntentUtils.openInBrowser(getContext(), selectedURL);
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
if(IntentUtils.isCallable(getActivity(), intent)) {
getActivity().startActivity(intent);
}
break; break;
case R.id.share_url_item: case R.id.share_url_item:
ShareUtils.shareLink(getActivity(), selectedURL); ShareUtils.shareLink(getActivity(), selectedURL);

View File

@ -15,6 +15,7 @@ import de.danoeh.antennapod.activity.AboutActivity;
import de.danoeh.antennapod.activity.BugReportActivity; import de.danoeh.antennapod.activity.BugReportActivity;
import de.danoeh.antennapod.activity.PreferenceActivity; import de.danoeh.antennapod.activity.PreferenceActivity;
import de.danoeh.antennapod.activity.StatisticsActivity; import de.danoeh.antennapod.activity.StatisticsActivity;
import de.danoeh.antennapod.core.util.IntentUtils;
public class MainPreferencesFragment extends PreferenceFragmentCompat { public class MainPreferencesFragment extends PreferenceFragmentCompat {
private static final String TAG = "MainPreferencesFragment"; private static final String TAG = "MainPreferencesFragment";
@ -72,11 +73,11 @@ public class MainPreferencesFragment extends PreferenceFragmentCompat {
} }
); );
findPreference(PREF_FAQ).setOnPreferenceClickListener(preference -> { findPreference(PREF_FAQ).setOnPreferenceClickListener(preference -> {
openInBrowser("https://antennapod.org/faq.html"); IntentUtils.openInBrowser(getContext(), "https://antennapod.org/faq.html");
return true; return true;
}); });
findPreference(PREF_VIEW_MAILING_LIST).setOnPreferenceClickListener(preference -> { findPreference(PREF_VIEW_MAILING_LIST).setOnPreferenceClickListener(preference -> {
openInBrowser("https://groups.google.com/forum/#!forum/antennapod"); IntentUtils.openInBrowser(getContext(), "https://groups.google.com/forum/#!forum/antennapod");
return true; return true;
}); });
findPreference(PREF_SEND_BUG_REPORT).setOnPreferenceClickListener(preference -> { findPreference(PREF_SEND_BUG_REPORT).setOnPreferenceClickListener(preference -> {
@ -85,16 +86,6 @@ public class MainPreferencesFragment extends PreferenceFragmentCompat {
}); });
} }
private void openInBrowser(String url) {
try {
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(myIntent);
} catch (ActivityNotFoundException e) {
Toast.makeText(getActivity(), R.string.pref_no_browser_found, Toast.LENGTH_LONG).show();
Log.e(TAG, Log.getStackTraceString(e));
}
}
private void setupSearch() { private void setupSearch() {
SearchPreference searchPreference = (SearchPreference) findPreference("searchPreference"); SearchPreference searchPreference = (SearchPreference) findPreference("searchPreference");
SearchConfiguration config = searchPreference.getSearchConfiguration(); SearchConfiguration config = searchPreference.getSearchConfiguration();

View File

@ -214,14 +214,7 @@ public class FeedItemMenuHandler {
DBWriter.setFeedItemAutoDownload(selectedItem, false); DBWriter.setFeedItemAutoDownload(selectedItem, false);
break; break;
case R.id.visit_website_item: case R.id.visit_website_item:
Uri uri = Uri.parse(FeedItemUtil.getLinkWithFallback(selectedItem)); IntentUtils.openInBrowser(context, FeedItemUtil.getLinkWithFallback(selectedItem));
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
if(IntentUtils.isCallable(context, intent)) {
context.startActivity(intent);
} else {
Toast.makeText(context, context.getString(R.string.download_error_malformed_url),
Toast.LENGTH_SHORT).show();
}
break; break;
case R.id.share_link_item: case R.id.share_link_item:
ShareUtils.shareFeedItemLink(context, selectedItem); ShareUtils.shareFeedItemLink(context, selectedItem);

View File

@ -86,14 +86,7 @@ public class FeedMenuHandler {
conDialog.createNewDialog().show(); conDialog.createNewDialog().show();
break; break;
case R.id.visit_website_item: case R.id.visit_website_item:
Uri uri = Uri.parse(selectedFeed.getLink()); IntentUtils.openInBrowser(context, selectedFeed.getLink());
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
if(IntentUtils.isCallable(context, intent)) {
context.startActivity(intent);
} else {
Toast.makeText(context, context.getString(R.string.download_error_malformed_url),
Toast.LENGTH_SHORT).show();
}
break; break;
case R.id.share_link_item: case R.id.share_link_item:
ShareUtils.shareFeedlink(context, selectedFeed); ShareUtils.shareFeedlink(context, selectedFeed);

View File

@ -1,13 +1,20 @@
package de.danoeh.antennapod.core.util; package de.danoeh.antennapod.core.util;
import android.content.ActivityNotFoundException;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;
import de.danoeh.antennapod.core.R;
import java.util.List; import java.util.List;
public class IntentUtils { public class IntentUtils {
private static final String TAG = "IntentUtils";
private IntentUtils(){} private IntentUtils(){}
/* /*
@ -28,4 +35,13 @@ public class IntentUtils {
context.sendBroadcast(new Intent(action).setPackage(context.getPackageName())); context.sendBroadcast(new Intent(action).setPackage(context.getPackageName()));
} }
public static void openInBrowser(Context context, String url) {
try {
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
context.startActivity(myIntent);
} catch (ActivityNotFoundException e) {
Toast.makeText(context, R.string.pref_no_browser_found, Toast.LENGTH_LONG).show();
Log.e(TAG, Log.getStackTraceString(e));
}
}
} }