Better handling of exception.
- Show an android toast when play store app is not available
on the device.
- Handle gracefully when exception occurs when enqueueing
a download.
Change-Id: Id3855394138e642b76ef89883960ee66be6c7323
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 0d50583..fb1ad41 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -76,6 +76,8 @@
<string name="title_bar_loading">Loading\u2026</string>
<!-- Message to be displayed if url character limit exceeds -->
<string name="max_url_character_limit_msg">Max URL limit reached</string>
+ <!-- Message to be displayed when google play store does not exist on the device -->
+ <string name="msg_no_google_play">Sorry, Google Play store app does not exist.</string>
<!-- Menu item -->
<string name="page_info">Page info</string>
diff --git a/src/com/android/browser/DownloadHandler.java b/src/com/android/browser/DownloadHandler.java
index f42ee76..ab24b76 100644
--- a/src/com/android/browser/DownloadHandler.java
+++ b/src/com/android/browser/DownloadHandler.java
@@ -112,7 +112,11 @@
.getSystemService(Context.DOWNLOAD_SERVICE);
new Thread("Browser download") {
public void run() {
- manager.enqueue(request);
+ try {
+ manager.enqueue(request);
+ } catch (Exception e) {
+ Log.w("DLHandler", "Could not enqueue the download", e);
+ }
}
}.start();
showStartDownloadToast(activity, privateBrowsing);
diff --git a/src/com/android/browser/UrlHandler.java b/src/com/android/browser/UrlHandler.java
index a3936b4..37480af 100755
--- a/src/com/android/browser/UrlHandler.java
+++ b/src/com/android/browser/UrlHandler.java
@@ -188,16 +188,25 @@
if (mActivity.getPackageManager().resolveActivity(intent, 0) == null) {
String packagename = intent.getPackage();
if (packagename != null) {
- intent = new Intent(Intent.ACTION_VIEW, Uri
- .parse("market://search?q=pname:" + packagename));
- intent.addCategory(Intent.CATEGORY_BROWSABLE);
- mActivity.startActivity(intent);
- // before leaving BrowserActivity, close the empty child tab.
- // If a new tab is created through JavaScript open to load this
- // url, we would like to close it as we will load this url in a
- // different Activity.
- mController.closeEmptyTab();
- return true;
+ try {
+ intent = new Intent(Intent.ACTION_VIEW, Uri
+ .parse("market://search?q=pname:" + packagename));
+ intent.addCategory(Intent.CATEGORY_BROWSABLE);
+ mActivity.startActivity(intent);
+ // before leaving BrowserActivity, close the empty child tab.
+ // If a new tab is created through JavaScript open to load this
+ // url, we would like to close it as we will load this url in a
+ // different Activity.
+ mController.closeEmptyTab();
+ return true;
+ } catch (ActivityNotFoundException e) {
+ Log.w(TAG, "Play store not found while searching for : " + packagename);
+ CharSequence alert = mActivity.getResources().getString(
+ R.string.msg_no_google_play);
+ Toast t = Toast.makeText(mActivity , alert, Toast.LENGTH_SHORT);
+ t.show();
+ return false;
+ }
} else {
return false;
}