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 



---

Monday, April 29, 2013

Monday, April 1, 2013

How to add Webview as a ListView item in android

Hello friends, :)

This is very easy process.
But when we add webviews as a row item in ListView that time Webview showing wrong url, Its a issue with custom ListView but for that we use holder to hold view.

But problem as it is with listview bcz at the time of loading webpag webview height increases as per webpages.

So for that issue. I write very efficient code. 
Its output look like WebView showing as listview row item.
I will explain as follows. Please check it.

Step 1.  main_relLay.xml
For adding scroll view and linear layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ScrollView
        android:id="@+id/scrollview"
        android:layout_width="fill_parent"
        android:layout_height="450dp" >

        <LinearLayout
            android:id="@+id/main_relLay"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#0B7A3B"
            android:orientation="vertical" >
        </LinearLayout>
    </ScrollView>

</RelativeLayout>

Description: ScrollView use for listview effect. Linear Layout have a dynamic content (WebView) of rows.

Step 2: row.xml
For ListView row item

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <RelativeLayout
        android:id="@+id/row_relLay"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#F70925" >

        <ProgressBar
            android:id="@+id/progressbar"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:visibility="visible" />

        <WebView
            android:id="@+id/row_webView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:visibility="gone" >
        </WebView>
    </RelativeLayout>

</LinearLayout>

Description: Create another xml for listview row items.

Java file :
Using LayoutInflater load view of row.xml for listview row.
And add this row.xml in main.xml linear layout its avaialable in scroll view, This is main linear layout provide listview effect.

Step A: LinearLayout relLay = (LinearLayout) findViewById(R.id.main_relLay);
Step B: LayoutInflater inflater = (LayoutInflater) getApplication()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Step C: View v_child = inflater.inflate(R.layout.row, null);
Step D:  relLay.addView(v_child);



For more information or help regarding that,
Contact:
Mail ID : ranjitvcsc@gmail.com

Wednesday, February 27, 2013

Push Notification (GCM,C2DM) in Android

"Push Notification" this is from iPhone,
In Android this is GCM(Google Cloud Messaging), C2DM.

Check this is best links for Android

***Source code for ANDROID also for OWN SERVER***
http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/

***GCM Architecture Overview***
http://developer.android.com/google/gcm/gcm.html
http://developer.android.com/google/gcm/gs.html

** Registering Process with GCM ***
http://fundroiding.wordpress.com/2012/06/29/google-cloud-messaging-for-android-gcm-simple-tutorial/

***C2DM***
http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html

NOTE:
Google has officially deprecated C2DM as of June 26,2012. This means that
C2DM has stopped accepting new users and quota requests. Existing C2DM
developers are encouraged to migrate to Google's new push service, called
GoogleCloud messaging for Android (GCM).
               ->From : https://docs.urbanairship.com/pages/viewpage.action?pageId=1509252

Friday, February 22, 2013

In Android how to storing and retrieving images as a BLOB from SQLite Database

This is 2 import link for storing and retrieving images as a BLOB from SQLite Database.

http://android-codes-examples.blogspot.in/2011/09/image-and-content-is-populated-from.html


http://sree.cc/google/storing-and-retriving-images-in-sqlite-database-in-android


> First link showing full process and also showing retrived data in listview.
> Second link have a code to convert online image as a BLOB and storing in SQLite DB. Also having the process of retrieving same image and convert in an bitmap format.