android - Uploading 4032x3024 / 12MP resolution camera image to server -


i found out why previous issue had photos rear camera on phone not uploading via android app occurring. camera resolution high @ 4032 x 3024 , megapixel count 12mp, noticed when lower qualities, work. seems can go high 4.7 megapixel quality. 12mp quality absolutely large? or there way reduce size before uploaded?

main activity

package com.example.stins.orbotcamera;  import android.manifest; import android.app.progressdialog; import android.content.context; import android.content.dialoginterface; import android.content.intent; import android.content.pm.packagemanager; import android.database.cursor; import android.graphics.bitmap; import android.graphics.color; import android.graphics.drawable.bitmapdrawable; import android.net.uri; import android.os.asynctask; import android.os.build; import android.os.environment; import android.provider.mediastore; import android.provider.settings; import android.provider.syncstatecontract; import android.support.design.widget.coordinatorlayout; import android.support.design.widget.floatingactionbutton; import android.support.design.widget.snackbar; import android.support.v4.app.activitycompat; import android.support.v4.content.contextcompat; import android.support.v4.content.fileprovider; import android.support.v7.app.alertdialog; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.support.v7.widget.toolbar; import android.util.base64; import android.util.log; import android.view.menu; import android.view.menuinflater; import android.view.menuitem; import android.view.view; import android.widget.edittext; import android.widget.imageview; import android.widget.textview; import android.widget.toast;  import net.gotev.uploadservice.multipartuploadrequest; import net.gotev.uploadservice.uploadnotificationconfig;  import java.io.bytearrayoutputstream; import java.io.file; import java.io.ioexception; import java.text.simpledateformat; import java.util.date; import java.util.hashmap; import java.util.uuid;  public class mainactivity extends appcompatactivity implements view.onclicklistener {      private floatingactionbutton fab;     private imageview imageview;     private uri file;     private gpstracker gps;     private edittext imagecomment;     private coordinatorlayout coordinatorlayout;     private textview imagelat, imagelong;     private string mlat, mlong;      public static final string upload_url = "http://192.168.1.77/uploadexamples/upload.php";      private bitmap bitmap;        @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          fab = (floatingactionbutton) findviewbyid(r.id.fab);         imageview = (imageview) findviewbyid(r.id.imageview);         imagecomment = (edittext) findviewbyid(r.id.imagecomment);         imagelat = (textview) findviewbyid(r.id.imagelat);         imagelong = (textview) findviewbyid(r.id.imagelong);          fab.setonclicklistener(this);          if (contextcompat.checkselfpermission(this, manifest.permission.camera) != packagemanager.permission_granted) {             fab.setenabled(false);             imagecomment.setenabled(false);             activitycompat.requestpermissions(this, new string[]{manifest.permission.camera, manifest.permission.write_external_storage,manifest.permission.read_external_storage, manifest.permission.access_fine_location, manifest.permission.access_coarse_location}, 0);         }       }       @override     public void onrequestpermissionsresult(int requestcode, string[] permissions, int[] grantresults) {         if (requestcode == 0) {             if (grantresults.length > 0 && grantresults[0] == packagemanager.permission_granted                     && grantresults[1] == packagemanager.permission_granted) {                 fab.setenabled(true);                 imagecomment.setenabled(true);             }              else{                 coordinatorlayout = (coordinatorlayout) findviewbyid(r.id.coordinatorlayout);                 final snackbar snackbar = snackbar                         .make(coordinatorlayout, "accept permissions use app", snackbar.length_indefinite);                 snackbar.setaction("ok", new view.onclicklistener() {                     @override                     public void onclick(view view) {                         intent = getbasecontext().getpackagemanager()                                 .getlaunchintentforpackage( getbasecontext().getpackagename() );                         i.addflags(intent.flag_activity_clear_top);                         startactivity(i);                     }                 });                  snackbar.setactiontextcolor(color.white);                  view sbview = snackbar.getview();                 textview textview = (textview) sbview.findviewbyid(android.support.design.r.id.snackbar_text);                 textview.settextcolor(color.gray);                   snackbar.show();         }           }      }        public void uploadimage() {         //getting name image         string name = imagecomment.gettext().tostring().trim();          //getting actual path of image         string path = getpath(file);           //uploading code         try {             string uploadid = uuid.randomuuid().tostring();              //creating multi part request             new multipartuploadrequest(this, uploadid, upload_url)                     .addfiletoupload(path, "image") //adding file                     .addparameter("name", name) //adding text parameter request                     .addparameter("latitude", mlat)                     .addparameter("longitude", mlong)                     .setnotificationconfig(new uploadnotificationconfig())                     .setmaxretries(2)                     .startupload(); //starting upload              log.d("upload", "uploadimage: " + path);          } catch (exception exc) {             toast.maketext(this, exc.getmessage(), toast.length_short).show();         }     }        public string getpath(uri uri) {         cursor cursor = getcontentresolver().query(uri, null, null, null, null);         if (cursor != null) {             cursor.movetofirst();         }         string document_id = null;         if (cursor != null) {             document_id = cursor.getstring(0);         }         if (document_id != null) {             document_id = document_id.substring(document_id.lastindexof(":") + 1);         }         if (cursor != null) {             cursor.close();         }          cursor = getcontentresolver().query(                 android.provider.mediastore.images.media.external_content_uri,                 null, mediastore.images.media._id + " = ? ", new string[]{document_id}, null);         if (cursor != null) {             cursor.movetofirst();         }         string path = null;         if (cursor != null) {             path = cursor.getstring(cursor.getcolumnindex(mediastore.images.media.data));         }         if (cursor != null) {             cursor.close();         }          return path;     }               @override     protected void onactivityresult(int requestcode, int resultcode, intent data) {          if (requestcode == 0 && resultcode == result_ok && data != null && data.getdata() != null) {             file = data.getdata();             try {                 bitmap = mediastore.images.media.getbitmap(getcontentresolver(), file);                 imageview.setimagebitmap(bitmap);                 imagecomment.setvisibility(view.visible);              } catch (ioexception e) {                 e.printstacktrace();             }         }            if (requestcode == 0) {             gps = new gpstracker(mainactivity.this);              if (resultcode == result_ok) {                 if (gps.cangetlocation()) {                     double latitude = gps.getlatitude();                     double longitude = gps.getlongitude();                       mlat = double.tostring(latitude);                      mlong = double.tostring(longitude);                      imagelat.settext(mlat);                     imagelong.settext(mlong);                      // \n new line                     //toast.maketext(getapplicationcontext(), "your location - \nlat: " + latitude + "\nlong: " + longitude, toast.length_long).show();                     coordinatorlayout = (coordinatorlayout) findviewbyid(r.id.coordinatorlayout);                      final snackbar snackbar = snackbar                             .make(coordinatorlayout, "current location recorded", snackbar.length_long);                      snackbar.setactiontextcolor(color.white);                      view sbview = snackbar.getview();                     textview textview = (textview) sbview.findviewbyid(android.support.design.r.id.snackbar_text);                     textview.setcompounddrawableswithintrinsicbounds(r.drawable.ic_location_on_white_24dp,0,0,0);                     textview.settextcolor(color.white);                       snackbar.show();                 } else {                     // can't location.                     // gps or network not enabled.                     // ask user enable gps/network in settings.                  }              } else if (resultcode == result_canceled) {                 // user cancelled image capture                 coordinatorlayout = (coordinatorlayout) findviewbyid(r.id.coordinatorlayout);                 final snackbar snackbar = snackbar                         .make(coordinatorlayout,"picture cancelled", snackbar.length_short);                  view sbview = snackbar.getview();                 textview textview = (textview) sbview.findviewbyid(android.support.design.r.id.snackbar_text);                 textview.setcompounddrawableswithintrinsicbounds(r.drawable.ic_cancel_white_24dp,0,0,0);                 textview.settextcolor(color.white);                  snackbar.show();             } else {                 // failed capture image                 coordinatorlayout = (coordinatorlayout) findviewbyid(r.id.coordinatorlayout);                 final snackbar snackbar = snackbar                         .make(coordinatorlayout,"error taking picture", snackbar.length_short);                  view sbview = snackbar.getview();                 textview textview = (textview) sbview.findviewbyid(android.support.design.r.id.snackbar_text);                 textview.setcompounddrawableswithintrinsicbounds(r.drawable.ic_error_outline_white_24dp,0,0,0);                 textview.settextcolor(color.white);                  snackbar.show();             }         }     }      @override     public boolean oncreateoptionsmenu(menu menu) {         menuinflater inflater = getmenuinflater();         inflater.inflate(r.menu.menu_main, menu);         return true;     }          @override     public boolean onoptionsitemselected(menuitem item) {         int id = item.getitemid();         switch (item.getitemid()) {             case r.id.action_send:                 if(imageview.getdrawable()==null){                     coordinatorlayout = (coordinatorlayout) findviewbyid(r.id.coordinatorlayout);                     final snackbar snackbar = snackbar                             .make(coordinatorlayout,"sorry, you'll need image that!", snackbar.length_short);                      view sbview = snackbar.getview();                     textview textview = (textview) sbview.findviewbyid(android.support.design.r.id.snackbar_text);                     textview.setcompounddrawableswithintrinsicbounds(r.drawable.ic_error_outline_white_24dp,0,0,0);                     textview.settextcolor(color.white);                      snackbar.show();                 }                 else {                     uploadimage();                 }                 return true;           }         return super.onoptionsitemselected(item);     }      @override     public void onbackpressed() {          new alertdialog.builder(this, r.style.theme_appcompat_dialog_alert)                 .settitle("exit")                 .setmessage("are sure want close orbot camera?")                 .setpositivebutton("yes", new dialoginterface.onclicklistener()                 {                     @override                     public void onclick(dialoginterface dialog, int which) {                         finish();                     }                  })                 .setnegativebutton("no", null)                 .show();       }      @override     public void onclick(view v) {          intent i;         if(v.getid()==r.id.fab)         {             intent intent = new intent();             intent.settype("image/*");             intent.setaction(intent.action_get_content);             startactivityforresult(intent.createchooser(intent, "select picture"), 0);          }      } } 


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -