Commits

Anonymous committed 3f68a15

Be defensive when launching actions for URIs.

Also, in the no handler case try to pretty
print the URI.

Change-Id: I630aff86d141e101b9a300105105b3a852dbe894

  • Participants
  • Parent commits 9260514

Comments (0)

Files changed (1)

File src/com/android/apps/tag/record/UriRecord.java

 import com.google.common.primitives.Bytes;
 
 import android.app.Activity;
+import android.content.ActivityNotFoundException;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
 import android.net.Uri;
 import android.nfc.NdefRecord;
 import android.telephony.PhoneNumberUtils;
+import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View.OnClickListener;
  * A parsed record containing a Uri.
  */
 public class UriRecord implements ParsedNdefRecord, OnClickListener {
+    private static final String TAG = "UriRecord";
+
     private static final class ClickInfo {
         public Activity activity;
         public Intent intent;
     @Override
     public View getView(Activity activity, LayoutInflater inflater, ViewGroup parent) {
         Intent intent = getIntentForUri();
+
+        // Lookup which packages can handle this intent.
         PackageManager pm = activity.getPackageManager();
         List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
         int numActivities = activities.size();
         if (numActivities == 0) {
             TextView text = (TextView) inflater.inflate(R.layout.tag_text, parent, false);
-            text.setText(mUri.toString());
+            text.setText(getPrettyUriString(activity));
             return text;
         } else if (numActivities == 1) {
             return buildActivityView(activity, activities.get(0), pm, inflater, parent);
         }
     }
 
+    /**
+     * Build a view to display a single activity that can handle this URI.
+     */
     private View buildActivityView(Activity activity, ResolveInfo resolveInfo, PackageManager pm,
             LayoutInflater inflater, ViewGroup parent) {
         Intent intent = getIntentForUri();
     @Override
     public void onClick(View view) {
         ClickInfo info = (ClickInfo) view.getTag();
-        info.activity.startActivity(info.intent);
-        info.activity.finish();
+        try {
+            info.activity.startActivity(info.intent);
+            info.activity.finish();
+        } catch (ActivityNotFoundException e) {
+            // The activity wansn't found for some reason. Don't crash, but don't do anything.
+            Log.e(TAG, "Failed to launch activity for intent " + info.intent, e);
+        }
     }
 
     public Uri getUri() {