Issue 521, avoid an NPE
[zxing.git] / android / src / com / google / zxing / client / android / share / ShareActivity.java
index 5dd33b1..696b389 100755 (executable)
@@ -26,6 +26,7 @@ import android.provider.Browser;
 import android.provider.Contacts;
 import android.provider.BaseColumns;
 import android.text.ClipboardManager;
+import android.util.Log;
 import android.view.View;
 import android.widget.Button;
 import com.google.zxing.BarcodeFormat;
@@ -41,6 +42,8 @@ import com.google.zxing.client.android.R;
  */
 public final class ShareActivity extends Activity {
 
+  private static final String TAG = ShareActivity.class.getSimpleName();
+
   private static final int PICK_BOOKMARK = 0;
   private static final int PICK_CONTACT = 1;
   private static final int PICK_APP = 2;
@@ -148,6 +151,10 @@ public final class ShareActivity extends Activity {
   }
 
   private void showTextAsBarcode(String text) {
+    Log.i(TAG, "Showing text as barcode: " + text);    
+    if (text == null) {
+      return; // Show error?
+    }
     Intent intent = new Intent(Intents.Encode.ACTION);
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
     intent.putExtra(Intents.Encode.TYPE, Contents.Type.TEXT);
@@ -163,6 +170,10 @@ public final class ShareActivity extends Activity {
    * @param contactUri A Uri of the form content://contacts/people/17
    */
   private void showContactAsBarcode(Uri contactUri) {
+    Log.i(TAG, "Showing contact URI as barcode: " + contactUri);
+    if (contactUri == null) {
+      return; // Show error?
+    }
     ContentResolver resolver = getContentResolver();
     Cursor contactCursor = resolver.query(contactUri, null, null, null, null);
     Bundle bundle = new Bundle();
@@ -223,6 +234,7 @@ public final class ShareActivity extends Activity {
       intent.putExtra(Intents.Encode.DATA, bundle);
       intent.putExtra(Intents.Encode.FORMAT, BarcodeFormat.QR_CODE.toString());
 
+      Log.i(TAG, "Sending bundle for encoding: " + bundle);
       startActivity(intent);
     }
   }