java - Not receiving the complete Base64 string sent from PHP -


i have application , need receive images database (before asks, yes needs database).
in php file send full complete string, in android receive half of string or so.
guys have tip on why happening?
can me?

code

serverrequest.java:

public void fetchservicofotodatainbackground(int codservico, getservicofotocallback usercallback) {     new fetchservicofotodataasynctasck(codservico, usercallback).execute(); }   public class fetchservicofotodataasynctasck extends asynctask<void, void, arraylist<string>> {     arraylist<string> ltservico;     int codservico;     getservicofotocallback servcallback;      public fetchservicofotodataasynctasck(int codservico, getservicofotocallback servicocallback) {         this.codservico = codservico;         this.servcallback = servicocallback; }      @override     protected arraylist<string> doinbackground(void... params) {         arraylist<string> returnedservico = null;         try {              url url = new url(server_address + "myphpfile.php");             httpurlconnection conn = (httpurlconnection) url.openconnection();             uri.builder builder = new uri.builder()                     .appendqueryparameter("codservico", this.codservico+"");             final string postparameters = builder.build().getencodedquery();             conn.setconnecttimeout(3000);             conn.setreadtimeout(3000);             conn.setrequestmethod("post");             conn.setfixedlengthstreamingmode(postparameters.getbytes().length);             conn.setrequestproperty("content-type", "application/x-www-form-urlencoded");             conn.setdoinput(true);             conn.setdooutput(true);              //send post out             printwriter pw = new printwriter(conn.getoutputstream());             pw.print(postparameters);             pw.close();             conn.connect();             string result = convertstreamtostring(conn.getinputstream());             jsonarray jarray = new jsonarray(result);             jsonobject json_data = null;             returnedservico = new arraylist<>();             (int = 0; < jarray.length(); i++) {                 json_data = jarray.getjsonobject(i);                 string imagem = json_data.getstring("fotoservico");                 returnedservico.add(imagem);             }         } catch (exception e) {              e.printstacktrace();             log.e("exception", "erro[" + e.getmessage() + "] ");         }         return returnedservico;     }      @override     protected void onpostexecute(arraylist<string> returnedservico) {         servcallback.done(returnedservico);         super.onpostexecute(ltservico);     } }  private static string convertstreamtostring(inputstream is) {      bufferedreader reader = new bufferedreader(new inputstreamreader(is));     stringbuilder sb = new stringbuilder();      string line = null;     try {         while ((line = reader.readline()) != null) {             sb.append(line + "\n");         }     } catch (ioexception e) {         e.printstacktrace();     } {         try {             is.close();         } catch (ioexception e) {             e.printstacktrace();         }     }     return sb.tostring(); } 

myactivity.java:

public class verfotoserv extends basenavegationactivity {  private linearlayout lnrverimages; private imageview imageview; int codservico=0;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.verfotoserv);     setrequestedorientation(activityinfo.screen_orientation_portrait);     lnrverimages = (linearlayout) findviewbyid(r.id.lnrimages);      final bundle extras = getintent().getextras();     if (extras != null) {         codservico = extras.getint("codservico");     }      serverrequests serverrequests = new serverrequests(this);     serverrequests.fetchservicofotodatainbackground(codservico, new getservicofotocallback() {         @override         public void done(arraylist<string> returnimagens) {             try {                 if (returnimagens == null) {                     throw new exception("não existem dados ou ocorreu um erro no servidor\ntente novamente mais tarde.");                 }                 (string imagem : returnimagens) {                     log.i("imagemrecebida",imagem);                     byte[] imageasbytes = base64.decode(imagem.getbytes(), base64.default);                     imageview = new imageview(verfotoserv.this);                     linearlayout.layoutparams params = new linearlayout.layoutparams(viewgroup.layoutparams.match_parent,                             viewgroup.layoutparams.wrap_content);                     params.setmargins(5, 5, 5, 5);                     imageview.setlayoutparams(params);                      imageview.setimagebitmap(bitmapfactory.decodebytearray(imageasbytes,0,imageasbytes.length));                     imageview.setadjustviewbounds(true);                     lnrverimages.addview(imageview);                 }             }             catch (exception erro){                 erro.printstacktrace();                 showerror(erro);             }         }     });  }  private void showerror(exception erro){     log.e("erro", erro.getmessage());     alertdialog.builder dialogbuilder=new android.app.alertdialog.builder(verfotoserv.this);     dialogbuilder.setmessage("erro:"+erro.getmessage());     dialogbuilder.setpositivebutton("ok", null);     dialogbuilder.show(); } } 

myactivity.xml:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">  <scrollview xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/scroll1"     android:layout_width="match_parent"     android:layout_height="wrap_content">      <linearlayout         android:id="@+id/lnrverimages"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="vertical">      </linearlayout> </scrollview> </linearlayout> 

myphpfile:

<?php include_once "ligarbd.php";  $codservico = $_post['codservico'];  $sql = "select * table codservico=".$codservico; $result = mysql_query($sql);  $imagens = array(); $i = 0; while ( $postdata = mysql_fetch_assoc($result) ) {     $imagens[$i][fotoservico]=base64_encode($postdata['fotoservico']);     $i = $i + 1; }  echo json_encode($imagens); ?> 

it mistake receiving needed change this

lnrverimages = (linearlayout) findviewbyid(r.id.lnrimages); 

to this

lnrverimages = (linearlayout) findviewbyid(r.id.lnrverimages); 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -