title: Android phone gap app restarts on image upload from camera
body: <p>This is my code</p>
  
  <pre><code>   package com.sp.spandroid;
  
      import android.app.Activity;
      import android.app.Notification;
      import android.app.NotificationManager;
      import android.app.PendingIntent;
      import android.content.Context;
      import android.content.Intent;
      import android.net.Uri;
      import android.os.Build;
      import android.os.Bundle;
      import android.os.Environment;
      import android.os.Parcelable;
      import android.provider.MediaStore;
      import android.util.Log;
      import android.webkit.ConsoleMessage;
      import android.webkit.ValueCallback;
      import android.webkit.WebChromeClient;
      import android.widget.Toast;
  
      import org.apache.cordova.*;
  
      import java.io.File;
  
      public class CordovaApp extends CordovaActivity
      {
          private JSBridge jsBridge;
         // public static Activity activity;
          public static ValueCallback&lt;Uri&gt; mUploadMessage;
          private Uri mCapturedImageURI = null;
          @Override
          public void onCreate(Bundle savedInstanceState)
          {
              super.onCreate(savedInstanceState);
              super.init();
            //  activity = this;
              // Set by &lt;content src="index.html" /&gt; in config.xml
              LOG.d("SPANDROID/CordovaApp/onCreate==&gt;","onCreate !!");
              jsBridge = new JSBridge(this, super.appView);
              super.appView.addJavascriptInterface(jsBridge, "jsBridge");
              super.appView.getSettings().setJavaScriptEnabled(true);
              super.appView.getSettings().setLoadWithOverviewMode(true);
  
              super.appView.getSettings().setAllowFileAccess(true);
              if(Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.JELLY_BEAN_MR1){
                  super.appView.getSettings().setMediaPlaybackRequiresUserGesture(false);
              }
  
              loadUrl(launchUrl);
              CordovaInterface cdv = (CordovaInterface)getContext();
              super.appView.setWebChromeClient(new CordovaChromeClient(cdv,super.appView) {
                  // openFileChooser for Android 3.0+
                  public void openFileChooser(ValueCallback&lt;Uri&gt; uploadMsg, String acceptType) {
  
                      CordovaApp.mUploadMessage = uploadMsg;
                      LOG.d("SPANDROID/CordovaApp/openFileChooser==&gt;","acceptType ==&gt;"+ acceptType);
                      try {
  
  
                          File imageStorageDir = new File(
                                  Environment.getExternalStoragePublicDirectory(
                                          Environment.DIRECTORY_PICTURES)
                                  , "sp");
  
                          if (!imageStorageDir.exists()) {
                              // Create AndroidExampleFolder at sdcard
                              imageStorageDir.mkdirs();
                          }
                          Intent i = new Intent(Intent.ACTION_GET_CONTENT);
                          i.addCategory(Intent.CATEGORY_OPENABLE);
  
                          if(acceptType.equals("video/*")){
                              LOG.d("SPANDROID/CordovaApp/openFileChooser==&gt;","inside video ==&gt;"+ acceptType);
                              i.setType("video/*");
                              File file = new File(
                                      imageStorageDir + File.separator + "VIDEO_"
                                              + String.valueOf(System.currentTimeMillis())
                                              + ".3gp");
                              final Intent captureIntent = new Intent(
                                      MediaStore.ACTION_VIDEO_CAPTURE);
                              mCapturedImageURI = Uri.fromFile(file);
                              captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
                              Intent chooserIntent = Intent.createChooser(i, "File Chooser");
  
                              // Set camera intent to file chooser
                              chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS
                                      , new Parcelable[] { captureIntent });
                              LOG.d("SPANDROID/CordovaApp/openFileChooser==&gt;","openFileChooser 11 !!");
                              this.cordova.getActivity().startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE);
                          }else {
                              // Create camera captured image file path and name
                              File file = new File(
                                      imageStorageDir + File.separator + "IMG_"
                                              + String.valueOf(System.currentTimeMillis())
                                              + ".jpg");
  
                              mCapturedImageURI = Uri.fromFile(file);
                              // Camera capture image intent
                              final Intent captureIntent = new Intent(
                                      android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
  
                              captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
                              i.setType("image/*");
                              Intent chooserIntent = Intent.createChooser(i, "File Chooser");
  
                              // Set camera intent to file chooser
                              chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS
                                      , new Parcelable[] { captureIntent });
                              LOG.d("SPANDROID/CordovaApp/openFileChooser==&gt;","openFileChooser 11 !!");
                              this.cordova.getActivity().startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE);
                          }
                          // Create file chooser intent
  
  
  
  
                      } catch (Exception e) {
                          Toast.makeText(getBaseContext(), "Camera Exception:" + e, Toast.LENGTH_LONG).show();
                      }
                  }
  
                  // For Android &lt; 3.0
                  @SuppressWarnings("unused")
                  public void openFileChooser(ValueCallback&lt;Uri&gt; uploadMsg) {
                      openFileChooser(uploadMsg, "");
                  }
  
                  // For Android  &gt; 4.1.1
                  @SuppressWarnings("unused")
                  public void openFileChooser(ValueCallback&lt;Uri&gt; uploadMsg, String acceptType, String capture) {
                      openFileChooser(uploadMsg, acceptType);
                  }
  
  
                  public boolean onConsoleMessage(ConsoleMessage cm) {
                      onConsoleMessage(cm.message(), cm.lineNumber(), cm.sourceId());
                      return true;
                  }
  
                  public void onConsoleMessage(String message, int lineNumber, String sourceID) {
                      Log.d("SPANDROID", "SPANDROID: " + message);
                  }
              });
  
          }
  
  
  
  
          @Override
          protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
              LOG.d("SPANDROID/CordovaApp/onActivityResult==&gt;","resultCode ==&gt;"+resultCode);
              LOG.d("SPANDROID/CordovaApp/onActivityResult==&gt;","mUploadMessage ==&gt;"+ CordovaApp.mUploadMessage);
             // LOG.d("SPANDROID/CordovaApp/onActivityResult==&gt;","intent.getData() ==&gt;"+intent.getData());
              // TODO Auto-generated method stub
              if(requestCode==CordovaChromeClient.FILECHOOSER_RESULTCODE)
              {
  
                  if (null ==  CordovaApp.mUploadMessage) {
                      return;
                  }
  
                  Uri result=null;
  
                  try{
                      if (resultCode != RESULT_OK) {
                          CordovaApp.mUploadMessage.onReceiveValue(null);
                          return;
                      } else {
  
                          // retrieve from the private variable if the intent is null
                          result = intent == null ? mCapturedImageURI : intent.getData();
                      }
                  }
                  catch(Exception e)
                  {
                    //  Toast.makeText(getApplicationContext(), "activity :"+e, Toast.LENGTH_LONG).show();
                  }
                  LOG.d("SPANDROID/CordovaApp/onActivityResult==&gt;","result ==&gt;"+result);
                  CordovaApp.mUploadMessage.onReceiveValue(result);
                  CordovaApp.mUploadMessage = null;
  
              }
          }
  
      }
  </code></pre>
  
  <p>onActivityResult it is gettting CordovaApp.mUploadMessage as null. App is restarting when i choose an image from camera and i am not able to upload the image. This is happening for some phones only. Phones like moto-e moto-g are showing upload issues</p>