Thursday, August 29, 2013

How to set link on phone number and email addresses available in TextView. Or How to use Linkify

Reference from : http://android-developers.blogspot.hu/2008/03/linkify-your-text.html

TextView tvDesc = (TextView) findViewById(R.id.tv_desc_data);
tvDesc.setText(details);
Linkify.addLinks(tvDesc, Linkify.ALL);


If we use Linkify.ALL then all phone numbers and emails in textview default set blue links(called hyperlink).
And when user click on this link automatically open call dialed pad or email box.

Wednesday, June 12, 2013

Friday, June 7, 2013

Android app not run in debug mode and showing “Waiting for Debugger” message?

Some devices will only let the debugger attach if the application has the android.permission.SET_DEBUG_APP permission set in its manifest file:

<manifest>
  <uses-permission android:name="android.permission.SET_DEBUG_APP"/>
</manifest> 


--
Reference from:
http://stackoverflow.com/questions/4375375/how-to-resolve-waiting-for-debugger-message 

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.

Friday, February 15, 2013

How to finish all Activity's running in background in Android

---------------------------------------------------------------------------
Hello All,

This is very easy solution for this question.

A->B->C->D

We start from A and now we are on D activity.

We used intent for jump one activity to another.

Note: yet we not use finish...

Means A,B,C is running in background...

So, therefore we need to finish all (A,B,C) activities from activity C.
--------------------------
Step 1 : Save A, B, C activity in static Activity Vector. Create Static class and create Activity Vector.

public class VARIABLES_STACK_RANJIT {
                 public static Vector<Activity> v_context = new Vector<Activity>();
}

Step 2 : Write following code in A,B,C activity
               i) VARIABLES_STACK_RANJIT.v_context.add(A.this);
               ii) VARIABLES_STACK_RANJIT.v_context.add(B.this);
               i) VARIABLES_STACK_RANJIT.v_context.add(C.this);

Step 3 : Write final code in D activity

Start loop and finish manually all saved activity.

                 for (int i = 0; i < VARIABLES_STACK.v_context.size(); i++) {
(VARIABLES_STACK.v_context.elementAt(i)).finish();
Log.e("Activity :" + i, "finished...");
}

---------------------------------------------------------------------------

Monday, February 4, 2013

Don't reload activity when orientation changes in an Android

Changes in an AndroidManifest.xml file
Set configChanges="----------" property in <activity> tag.

Example:
android:configChanges="orientation|screenSize"

If we use this property then do not reload activity after changing the orientation (Portrait/Landscape).

Thursday, January 31, 2013

Online Compiler for compile all languages code

Hello friends,

Very tedious task to install all programming languages editor in an machine..

Avoid above step if you have internet.
Check this link for online compilers...


1. http://codepad.org/
2. http://www.compileonline.com/compile_cpp_online.php 

Friday, January 25, 2013

Create bitmap image of selected layout in android


----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------

//This is your layout and image view 

ImageView imgView = (ImageView) findViewById(R.id.imageView1);
RelativeLayout rLayout1 = (RelativeLayout) findViewById(R.id.relativeLayout1);


. . .
. . .
. . .
. . .
. . .

//Code for create bitmap image from selected portion of layout.
//After that created bitmap image set in an image view

View v1 = rLayout1;    
v1.setDrawingCacheEnabled(true);
Bitmap bitmap = v1.getDrawingCache();
//BitmapDrawable drawable = new BitmapDrawable(bitmap);
imgView.setImageBitmap(bitmap);


----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------

Send image to a webserver in Android or Java

This is very helpful example to send image on webserver.

http://www.marceloduende.com/blog/?p=1

This is source code from above link...
Is this very helpful. I used this technique in my Android code.
------------------------------------------------------------------------------------------------

// create a bitmap variable before anything;

private Bitmap bitmap;

// variable to set a name to the image into SD card;
// this variable, you have to put the path for the File, It's up to you;

public static String exsistingFileName;

// sendData is the function name, to call it, you can use something like sendData(null);
// remember to wrap it into a try catch;

public void sendData(String[] args) throws Exception {
try {

HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();

// here, change it to your php;

HttpPost httpPost = new HttpPost("http://www.myURL.com/myPHP.php");
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
bitmap = BitmapFactory.decodeFile(exsistingFileName);

// you can change the format of you image compressed for what do you want;
//now it is set up to 640 x 480;

Bitmap bmpCompressed = Bitmap.createScaledBitmap(bitmap, 640, 480, true);
ByteArrayOutputStream bos = new ByteArrayOutputStream();

// CompressFormat set up to JPG, you can change to PNG or whatever you want;

bmpCompressed.compress(CompressFormat.JPEG, 100, bos);
byte[] data = bos.toByteArray();

// sending a String param;

entity.addPart("myParam", new StringBody("my value"));

// sending a Image;
// note here, that you can send more than one image, just add another param, same rule to the String;

entity.addPart("myImage", new ByteArrayBody(data, "temp.jpg"));

httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost, localContext);
BufferedReader reader = new BufferedReader(new InputStreamReader( response.getEntity().getContent(), "UTF-8"));
String sResponse = reader.readLine();

} catch (Exception e) {

Log.v("myApp", "Some error came up");

}

}


------------------------------------------------------------------------------------------------------

Thursday, January 17, 2013

How to compare dates in Android

Manually we can compare dates..
But this is very tedious process....

We have simple techniques..
With the help of this we can compare dates with each other...

Follow this links...
1. http://www.mkyong.com/java/how-to-compare-dates-in-java/
2. http://atanu09.wordpress.com/2012/03/10/android-compare-two-dates/
3. http://www.roseindia.net/java/example/java/util/CompareDate.shtml

---------------------------------------------------X-----------------------------------------------------