Thursday 23 January 2014

How email in android programmatically.

In Today's Tutorial I am going to explain you how to you can mail the details to any email id. The email is generally used when we want to have feedback from the application user. like in contact us form or feedback form.

In this project I am creating a contact us form where i will get the name, address, mobile no, company name, email from the user and will send it to a particular email id.

So lets start.

1. create a XML layout file like this one ..

<?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:background="#659b40"
    android:orientation="vertical" >

    <FrameLayout
        android:id="@+id/frameLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#555555" >

        <ScrollView
            android:id="@+id/ScrollView1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:paddingLeft="30dp"
                android:paddingRight="30dp"
                android:paddingTop="15dp" >

                <EditText
                    android:id="@+id/yourname"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    android:background="@drawable/buttonstyle"
                    android:ems="10"
                    android:hint="Enter Name"
                    android:paddingBottom="5dp"
                    android:paddingLeft="20dp"
                    android:paddingRight="30dp"
                    android:paddingTop="5dp"
                    android:textColorHint="#000000"
                    android:textSize="25sp" >

                    <requestFocus />
                </EditText>

                <EditText
                    android:id="@+id/yournumber"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="10dp"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/buttonstyle"
                    android:ems="10"
                    android:hint="Enter Contact No"
                    android:inputType="phone"
                    android:paddingBottom="5dp"
                    android:paddingLeft="20dp"
                    android:paddingTop="5dp"
                    android:textColorHint="#000000"
                    android:textSize="25sp" />

                <EditText
                    android:id="@+id/youremail"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/buttonstyle"
                    android:ems="10"
                    android:hint="Enter Email Id"
                    android:inputType="textEmailAddress"
                    android:paddingBottom="5dp"
                    android:paddingLeft="20dp"
                    android:paddingTop="5dp"
                    android:textColorHint="#000000"
                    android:textSize="25sp" />

                <EditText
                    android:id="@+id/company_name"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/buttonstyle"
                    android:ems="10"
                    android:hint="Company Name"
                    android:paddingBottom="5dp"
                    android:paddingLeft="20dp"
                    android:paddingTop="5dp"
                    android:textColorHint="#000000"
                    android:textSize="25sp" />

                <EditText
                    android:id="@+id/conatct_address"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/buttonstyle"
                    android:ems="10"
                    android:hint="Address"
                    android:paddingBottom="5dp"
                    android:paddingLeft="20dp"
                    android:paddingTop="5dp"
                    android:textColorHint="#000000"
                    android:textSize="25sp" />

                <Button
                    android:id="@+id/yoursubmiot"
                    android:layout_width="fill_parent"
                    android:layout_height="50dp"
                    android:layout_marginTop="20dp"
                    android:background="@drawable/black_button"
                    android:text="Submit"
                    android:textColor="#999999"
                    android:textSize="20sp"
                    android:textStyle="bold" />
            </LinearLayout>

        </ScrollView>

    </FrameLayout>

</LinearLayout>

2. Now comes the coding part..... so lets start.

  firstly we will initialize the edit text's and submit button

        submit=(Button)findViewById(R.id.yoursubmiot);
        Name=(EditText)findViewById(R.id.yourname);
        contactno=(EditText)findViewById(R.id.yournumber);
        emailid=(EditText)findViewById(R.id.youremail);
        company_name=(EditText)findViewById(R.id.company_name);
        address=(EditText)findViewById(R.id.conatct_address);

Second now on submit button set onclick listener and put the following code in that


                        name = Name.getText().toString();
                        contact = contactno.getText().toString();
                        email = emailid.getText().toString();
                        company = company_name.getText().toString();
                        addr=address.getText().toString();

                        String to = "itdevelopersdelhi@gmail.com";
                        String message = "Name Of Customer   "
                            + name   +"\n"
                            + "      contact no       "
                            + contact
                            + ".....email id ..........."
                            + email
                            + ".........Company name........."
                            + company+"........"
                            + ".........Address........"
                            + addr
                            +".............";
                       
                        Intent email = new Intent(Intent.ACTION_SEND);
                        email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to});
                        email.putExtra(Intent.EXTRA_SUBJECT, "Customer Query ");
                        email.putExtra(Intent.EXTRA_TEXT, message);
                        email.setType("message/rfc822");
                        startActivity(Intent.createChooser(email, "Choose an Email client :"));
                     }
                  
In the above code we have implemented the intent and the action on intent is set to action send. and added the email id ,subject, and text. In text we have added all details which we have got from the user since it is of string type.

The Intent is set to the message/rfc822 . and at last we will start the activity.

In the project I have added added few more thinks. which you can see after downloading the project the project download link is given below.

Snapshots:-









https://adf.ly/cVYLmDownload the project

Tuesday 21 January 2014

How to look the values of android sqlite database.

In Today's tutorial i am going to explain how we can the see the values of the table that you have created in android my help of SQLiteOpenHelper. as we know that if we want to give some interactivity to an android application

we have to use database in android application. because we could be required to store the information in the application. but while implementing the database we faces many problems like usually we don't know values which our variable hold we try to access the value which is not present in the table.

So lets start .....

1. download the this jar file from here and put it into Eclipse/dropins/

2. Now restart your eclipse.

3 After restarting click on the DDMS located at the Top of the right side.


4. if there is no DDMS then go to the Window/Our perspective/ and the DDMS


5. now on the left hand side your emulator will be displayed select the application package in which you have created the table.

6. On the right hand side select the file explorer. then go to this path
(data/data/your.package.name/databases/select the .db extension file) 


7. now on the right hand side the database icon will gets blue.


8. Click on it ......... after click a Questoid SQLite Browser will appear at the bottom. Now click on the Browse data and select your table.



9. Now you can see the values of the table.


Monday 20 January 2014

Smart Contact Lens Product from Google



Here is the good news from the search engine giant. Google has made a contact lens that will analysis the glucose present in your tear and

if the sugar level goes high in the tear the circuit in the lens start's glowing. It also sense whether the sugar level is below to the normal

The product is still under the testing phase we have to wait little more to get this amazing product.

for more details click below.....

Monday 6 January 2014

Simple Implementation of ListView in Android.

In the last tutorial I have showed how we can implement a GridView in android now i will show how we can add a array of string in an List View without using a BaseAdapter Class . Adding a String array in ListView is considered to be a most simple way to use an ListView. List View is easy and attractive way to display the data Now days you will see that the most of the application uses the list view and by this the application also look attractive. So lets start.

First Step :-
           
Take a list view in your activity_main XML file like this.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" >
    </ListView>

</RelativeLayout>

Second Step:-

Now create another XMl file and put an TextView in it. Name the file as list_item.xml.

<?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" >
   
    <!-- Single ListItem -->
   
    <!-- Product Name -->
    <TextView android:id="@+id/product_name"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dip"
        android:textSize="16dip"
        android:textStyle="bold"/>   

</LinearLayout>

Third Step:-

Now comes to source code open the MainActivity and the create a string array, ListView and ArrayAdapter.

private final String[] Itdelhi = new String[]
{"ItDevelopersDelhi","Android","SEO","Wed Development" };
ArrayAdapter<String> adapter;
ListView lv;

 put the following code in oncreate function.

 lv = (ListView) findViewById(R.id.list);
 adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.product_name, Itdelhi);
 lv.setAdapter(adapter);

Now we are ready to execute the code.

Snapshots:-






Friday 3 January 2014

Simple Implementation of GridView in Android

Today I am going to explain you How you u can implement a grid view and put button in the cells of grid view. Grid view is used to render a view at your own or we can say that you can customize the a group of objects by your own suppose you want a create a horizontal list of weekdays

which i am going to explain in this tutorial So for that some of you would take a image and put it in a button or image view or some of you will create a separate widget of each day.


But the easiest method would be the implementation of grid view. Its an example you can create an list or any view by using grid view.So lets start

1. create a layout file with the name gridcell and put following XML code in that.

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <Button
        android:id="@+id/gridcell"
        android:layout_gravity="center"
        android:textColor="#FFFFFF"
        android:background="@drawable/calendar_button_selector"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </Button>
</LinearLayout>

 2. Now put the following code in your main XML file

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity"
    >
    <GridView
        android:id="@+id/days"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:horizontalSpacing="-1px"
        android:numColumns="7"
        android:verticalSpacing="-1px" >
    </GridView>
</RelativeLayout>

 3. Now comes the coding part. Create a class Days and extend it with BaseAdapter. and put the following code


Context context;
    private final List<String> list;
    private Button gridcell;
    String[] week;
   
    public Days(Context applicationContext, int gridcell, String[] weekdays) {
        // TODO Auto-generated constructor stub
               
                this.context=applicationContext;
                this.week=weekdays;
                this.list = new ArrayList<String>();
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return week.length;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
       
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.gridcell, parent, false); 
        gridcell = (Button) convertView.findViewById(R.id.gridcell);
        gridcell.setText(week[position].toString());
       
        return convertView;
    }


4. Fourth and final step create a object of the Days class and initialize it after and initialize the grid view also.

Days dayAdapter;
GridView days;
 private final String[] weekdays = new String[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };


after this put days variable as a set adapter object.


  dayAdapter= new Days(this, R.id.gridcell,weekdays);
  days=(GridView)findViewById(R.id.days);
       
  days.setAdapter(dayAdapter);


Snapshots:-





https://adf.ly/bYMfSClick to Download The Project