Tuesday 23 June 2015

Read Contact in Android Mobile.


                                            Read Contacts in Android Mobile Application.



Step 1:-

MainActivity.java

package com.example.readcontacts;

import java.io.IOException;


import android.support.v7.app.ActionBarActivity;

import android.database.Cursor;
import android.database.CursorIndexOutOfBoundsException;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {


@Override

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

try {


readAllContacts();


} catch (IOException e) {

// TODO Auto-generated catch block
e.printStackTrace();
}

}


@Override

public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override

public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}

public void readAllContacts() throws IOException {

String[] contacts = new String[] {
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER };

String name = null;

String phonenumber = null;

TextView txt = (TextView) findViewById(R.id.readcontact_results);

Cursor cursorphoneContacts = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, contacts,
null, null,
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " Asc");

try {


} catch (CursorIndexOutOfBoundsException o) {

System.out.println("Error" + o);
}

if (cursorphoneContacts != null && cursorphoneContacts.getCount() > 0) {

cursorphoneContacts.moveToFirst();
do {

name = cursorphoneContacts.getString(cursorphoneContacts

.getColumnIndex(Contacts.DISPLAY_NAME));
phonenumber = cursorphoneContacts
.getString(cursorphoneContacts
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
txt.append("\nName-->" + name + "\n");
txt.append("Phone Number-->" + phonenumber + "\n\n\n");

} while (cursorphoneContacts.moveToNext());


cursorphoneContacts.close();

} else {
Toast.makeText(getApplicationContext(), "There is no Contacts...",
Toast.LENGTH_LONG).show();
}

}



}

Step 2:-

activity_main.xml

<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.readcontacts.MainActivity" >

    <TextView
        android:id="@+id/readcontact_results"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="74dp"
        android:text="TextView" />

</RelativeLayout>


Step 3:-


AndroidManifest.xml


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


Step 4 :-

Screenshot:-








Source Code:-

                                         Full Source Code for read contacts in mobile.



Reference:

                                         Full Source code for Read contact using Autocomplete



Monday 22 June 2015

ActionBar image attachment example with source code


                                               ActionBar Example in android





main.xml


<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.androidactionbarexample.MainActivity" >

   
    <item
        android:id="@+id/action_refresh"
        android:icon="@drawable/sync_icons"
        android:orderInCategory="100"
        android:showAsAction="always"
        android:title="Refresh"/>

</menu>


MainActivity.java


package com.example.androidactionbarexample;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// action with ID action_refresh was selected
case R.id.action_refresh:
Toast.makeText(this,
"your select Sync Icon to Refresh selected all service.",
Toast.LENGTH_SHORT).show();
break;

default:
break;
}

return true;
}

}


Example Screen Shot:






Example Code :

                                              Full Source code for ActionBar


Another Example  Screen:








Example Source Code:

                                  Actionbarsherlock lib code

                                  Example Source code for Different Types of Actionbar




Saturday 20 June 2015

finger based zoomming in android


                                    Zooming Layout in Android

Java File Main Activity:

package com.example.fingerbasedzoom;

import pl.polidea.view.ZoomView;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout.LayoutParams;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;

public class MainActivity extends ActionBarActivity {

private ZoomView zoomView;
LinearLayout main_container;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

View v = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.framed, null, false);
v.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

zoomView = new ZoomView(this);
zoomView.addView(v);

main_container = (LinearLayout) findViewById(R.id.linear_fuc1);
main_container.addView(zoomView);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}



activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
android:id="@+id/linear_fuc1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>

</LinearLayout>


framed.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/darkgreen" >

<LinearLayout
android:id="@+id/frade"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/blue"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hi This is chandru"
android:textColor="#000"
android:textSize="10dp" />

<TextView
android:layout_width="fill_parent"
android:layout_height="83dp"
android:gravity="right"
android:text="bottom text"
android:textColor="#fff"
android:textSize="20dp" />

<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />

<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />

<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />

<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />

<Button
android:id="@+id/button5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />

<Button
android:id="@+id/button6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />

<ScrollView
android:id="@+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />

<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >

<requestFocus />
</EditText>

<Button
android:id="@+id/button7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />

<Button
android:id="@+id/button8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />

<Button
android:id="@+id/button9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />

<Button
android:id="@+id/button10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />

<Button
android:id="@+id/button11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</ScrollView>
</LinearLayout>

</FrameLayout>



Screen:

Before Zoom Image





After Zoom Image







Source Code Download From Link:

                            Full source code for finger based zooming.













Wednesday 17 June 2015

push notification google cloud message.



                                          Google Cloud Message




Source code link


download from full android gcm code.

Friday 12 June 2015

How to get the browser history.


                                     Browser history viewing using android 



This code working on google chrome only.


java file.   both of the code are working fine.


import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Browser;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class BrowserHistory extends Activity {

    Button btn_history;
   
   
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_browser_history);
       
       
       
        btn_history = (Button)findViewById(R.id.btn_history);
        btn_history.setOnClickListener(new View.OnClickListener() {
           
            @Override
            public void onClick(View v) {
               
               
                String[] proj = new String[] { Browser.BookmarkColumns.TITLE, Browser.BookmarkColumns.URL };
                String sel = Browser.BookmarkColumns.BOOKMARK + " = 0"; // 0 = history, 1 = bookmark
                Cursor mCur = getContentResolver().query(Browser.BOOKMARKS_URI, proj, sel, null, null);
                mCur.moveToFirst();
                String title = "";
                String url = "";
                if (mCur.getCount()> 0 && mCur !=null) {
                    boolean cont = true;
                    while (mCur.isAfterLast() == false && cont) {
                        title = mCur.getString(mCur.getColumnIndex(Browser.BookmarkColumns.TITLE));
                        url = mCur.getString(mCur.getColumnIndex(Browser.BookmarkColumns.URL));
                        // Do something with title and url
                       
                       
                        Log.i("History of Browser URL Titles:","Titles"+title);
                        Log.i("History of Browser URL Titles:","URL"+url);
                       
                       
                       
                        mCur.moveToNext();
                    }
                }




               
            }
        });
       

//this one for toast
        Cursor mCur =this.managedQuery(Browser.BOOKMARKS_URI,
                Browser.HISTORY_PROJECTION, null, null, null);
        mCur.moveToFirst();
        if (mCur.moveToFirst() && mCur.getCount() > 0) {
            while (mCur.isAfterLast() == false) {
                Toast.makeText(
                        BrowserHistory.this,
                        mCur.getString(Browser.HISTORY_PROJECTION_TITLE_INDEX),
                        Toast.LENGTH_LONG).show();
                Toast.makeText(
                        BrowserHistory.this,
                        mCur.getString(Browser.HISTORY_PROJECTION_URL_INDEX),
                        Toast.LENGTH_LONG).show();
                mCur.moveToNext();
            }

        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.browser_history, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}



Androidmanifest.xml

    <uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" />




If this code is not working.that is You getting error example. mCur null pointer exception in Runtime(RuntimeException). that time once your google chrome it open check the history data,then run again. It's work fine.