Android for Ksoap2, upload photo
<p><strong>As part of my project I need to upload an image to the server. In the server part I have a web service that will accept byte array and converting in to image. In my client part(Android + ksoap2) I converted the image to byte[] array using Base64 encoding.</strong></p>

<p>dont upload photo....</p>

<ul>
<li><p>Android main java</p>

<pre><code>public class DataHandlerSoapActivity extends Activity {

    private String SOAP_ACTION="http://tempuri.org/savaPhoto1"; //"http://tempuri.org/forTest";
    private String METHOD_NAME="savaPhoto1";
    private String NAMESPACE="http://tempuri.org/"; //"http://tempuri.org/";
    private final String URL="http://192.168.0.2:8080/FinlandWebservice/Service.asmx";
    private ImageView iv;
    private Bitmap bit;
    private EditText e_text;
    TextView tv;
    private Uri imgUri;

    final static int GALLERY_RESULT = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        iv = (ImageView) findViewById(R.id.imgView);
        e_text = (EditText) findViewById(R.id.editText1);
    }   

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);

        try {
            imgUri = data.getData();
            bit = Images.Media.getBitmap(getContentResolver(), imgUri);

            iv = (ImageView) findViewById(R.id.imgView);
            iv.setImageBitmap(bit);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void onClickImg(View v) throws IOException {
        switch(v.getId()) { 
        case R.id.camera:   

            //          takePicture();
            Intent i = new Intent();
            i.setAction(Intent.ACTION_GET_CONTENT);
            i.setType("image/*");
            startActivityForResult(i, GALLERY_RESULT);
            break;
        case R.id.photoAlbum:           

            break;

        case R.id.trans:            

            break;

        case R.id.web_btn:      
            testWebService();
            //           String strRval = soapCommunication();         
            //              r_text.setText("Result Value : " + strRval);    
            break;
        }
    }
    public void testWebService() throws IOException{         
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();     
        StrictMode.setThreadPolicy(policy);
        try {           
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);


            ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
            bit.compress(Bitmap.CompressFormat.JPEG, 100, byteArray);
            byte[] b = byteArray.toByteArray();         
            String s = Base64.encodeBytes(b);

            request.addProperty("txt", e_text.getText().toString());
            request.addProperty("image", s);


            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);

            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            HttpTransportSE aht = new HttpTransportSE(URL);         

            aht.call(SOAP_ACTION, envelope);

            Toast.makeText(DataHandlerSoapActivity.this, "good", Toast.LENGTH_SHORT).show();


        } catch (Exception e) {
            Toast.makeText(DataHandlerSoapActivity.this, "err", Toast.LENGTH_SHORT).show();
        }       

    }


}
</code></pre></li>
<li><p>android XML</p>

<pre><code>&lt;LinearLayout
    android:id="@+id/layout3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" &gt;

    &lt;Button
        android:id="@+id/camera"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onClickImg"
        android:text="@string/camera" /&gt;

    &lt;Button
        android:id="@+id/photoAlbum"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onClickImg"
        android:text="@string/photoAlbum" /&gt;

    &lt;Button
        android:id="@+id/trans"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onClickImg"
        android:text="trans" /&gt;
&lt;/LinearLayout&gt;

&lt;LinearLayout
    android:id="@+id/layout2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" &gt;

    &lt;Button
        android:id="@+id/web_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onClickImg"
        android:text="web" /&gt;

    &lt;EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1.25"
        android:ems="10" &gt;

        &lt;requestFocus /&gt;
    &lt;/EditText&gt;

&lt;/LinearLayout&gt;

&lt;ImageView
    android:id="@+id/imgView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" /&gt;
</code></pre></li>
<li><p>Manifast</p>

<p></p></li>
</ul>
