Saturday, May 25, 2013

How to uploading Image/file from Android to .Net WCF And send XML file also.

With the help of following code or link we can easily upload image or any file from Android to .NET WCF.

This is code to upload image on .net wcf

    URL url = null;
        HttpURLConnection conn = null;
        DataOutputStream dos = null;
        DataInputStream inStream = null;
        String existingFileName = null;

        existingFileName = my_gallary_selected_img_path;
        int bytesRead, bytesAvailable, bufferSize;
        byte[] buffer;
        int maxBufferSize = Integer.MAX_VALUE;
        String responseFromServer = "";

       url = new URL(my_webservice);

        try {
                   FileInputStream fileInputStream = new FileInputStream(new File(
                    existingFileName));

            // Open a HTTP connection to the URL
            conn = (HttpURLConnection) url.openConnection();
            // Allow Inputs
            conn.setDoInput(true);
            // Allow Outputs
            conn.setDoOutput(true);
            // Don't use a cached copy.
            conn.setUseCaches(false);
            // Use a post method.

            StringBuilder sb = new StringBuilder();

            boolean genderStatus;
            if (radioGenderButton.getText().toString().trim().equals("Male")) {
                genderStatus = true;
            } else {
                genderStatus = false;
            }

            // sb.append("<Result> <ServiceAuthToken>XadGenAuth123</ServiceAuthToken> <UserAuthToken>e6c53849-d78b-49cf-b59f-7d36b19bd220</UserAuthToken> <ContactId>19</ContactId> <ContactsXml> <Contact> <ContactId>19</ContactId> <FirstName>Ranjit</FirstName>    <LastName>Chandel</LastName> <Gender>true</Gender>    <Age>37</Age>  <Company>RedOrange</Company>    <Email>vikas@test.com</Email> <Address>Chs</Address>    <State>Chandigarh</State>    <Zip>42342355</Zip>    <Country>United States</Country>    <SkypeId />    <Interest>1-2-3</Interest>    </Contact>    </ContactsXml>    </Result>");
            conn.setRequestMethod("POST");
            conn.setRequestProperty("ContactXmlFile", "" + sb);
           
            dos = new DataOutputStream(conn.getOutputStream());
            bytesAvailable = fileInputStream.available();
            bufferSize = Math.min(bytesAvailable, maxBufferSize);
            buffer = new byte[bufferSize];
            // read file and write it into form...
            bytesRead = fileInputStream.read(buffer, 0, bufferSize);
            while (bytesRead > 0) {
                dos.write(buffer, 0, bufferSize);
                bytesAvailable = fileInputStream.available();
                bufferSize = Math.min(bytesAvailable, maxBufferSize);
                bytesRead = fileInputStream.read(buffer, 0, bufferSize);

            }
            fileInputStream.close();
            dos.flush();
            dos.close();
        } catch (MalformedURLException ex) {
            Log.e("Debug", "error: " + ex.getMessage(), ex);
        } catch (IOException ioe) {
            Log.e("Debug", "error: " + ioe.getMessage(), ioe);
        }
        // ITS SERVER RESPONSE
        try {
            inStream = new DataInputStream(conn.getInputStream());
            String str;

            while ((str = inStream.readLine()) != null) {
                Log.e("Debug", "Server Response " + str);
                // statuss.setText(str);
            }
            inStream.close();

        } catch (IOException ioex) {
            Log.e("Debug", "error: " + ioex.getMessage(), ioex);
        }

Reference from:
Please check this stack overflow link also:
http://stackoverflow.com/questions/7860298/uploading-ms-word-files-from-android-to-net-wcf/8209430#8209430

Friday, May 24, 2013

Saturday, May 18, 2013

Use Google Map in Android using V2 API key

NOTE: Version 1 of the Google Maps Android API has been officially deprecated as of December 3rd, 2012 . This means that from March 3rd , 2013 you will no longer will able to request an API key for this  version. No new features will be added to Google Maps API v1 . However , apps using v1 will continue work on devices. Existing and new developers are encouraged to use Google Maps Android API v2.

NOTE: You cannot run your application using Google Play API(Google Maps Android API V2) on Android emulator, Because your emulator doesn't support Google Play services. So you need to check your application in Android mobile phone which supports google play services.


Please! Check following link.
This is vet helpful. All introduction about that available in a single page.

http://ramsandroid4all.blogspot.in/2013/03/google-maps-android-api-v2.html 



---