Friday 13 December 2013

Android : Open URL on button click.

In this tutorial we will learn how to open URL on button click.

1. Create New Android Application Project. Name it as UrlButton.








2. Open Your activity_main.xml file.
3. Replace your activity_main.xml code with below code.


<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=".MainActivity" >

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

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="35dp"
        android:text="Open URL " />

</RelativeLayout>

 Your activity_main.xml will look like below

5 . Open your Mainactivity.java file.

6 . Replace Your Mainactivity.java code with below code.
 

package arshad.urlbutton;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;


public class MainActivity extends Activity {
 Button button1;
       @Override
       protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              button1=(Button)findViewById(R.id.button1);
             
              button1.setOnClickListener(new OnClickListener() {

                     @Override
                     public void onClick(View arg0) {
                           Intent intent =new Intent(Intent.ACTION_VIEW,Uri.parse("http://technologyarshadshaikh.blogspot.in"));
                           startActivity(intent); 
                          
                     }
       });
       }

       @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;
       }

}

 7. Now Build And Run Your Application.

You will be redirected to the url on button click
All The Best.

Tuesday 12 November 2013

Android : Features

Features of Android


As Android is open source and freely available to manufacturers for customization, there are no fixed
hardware and software configurations. However, Android itself supports the following features:


➤➤ Storage — Uses SQLite, a lightweight relational database, for data storage. Chapter 6 discusses
data storage in more detail.


➤➤ Connectivity — Supports GSM/EDGE, IDEN, CDMA, EV-DO, UMTS, Bluetooth (includes
A2DP and AVRCP), WiFi, LTE, and WiMAX. Chapter 8 discusses networking in more detail.


➤➤ Messaging — Supports both SMS and MMS. Chapter 8 discusses messaging in more detail.


➤➤ Web browser — Based on the open-source WebKit, together with Chrome’s V8 JavaScript engine


➤➤ Media support — Includes support for the following media: H.263, H.264 (in 3GP or MP4
container), MPEG-4 SP, AMR, AMR-WB (in 3GP container), AAC, HE-AAC (in MP4 or
3GP container), MP3, MIDI, Ogg Vorbis, WAV, JPEG, PNG, GIF, and BMP


➤➤ Hardware support — Accelerometer Sensor, Camera, Digital Compass, Proximity Sensor,
and GPS


➤➤ Multi-touch — Supports multi-touch screens


➤➤ Multi-tasking — Supports multi-tasking applications


➤➤ Flash support — Android 2.3 supports Flash 10.1.


➤➤ Tethering — Supports sharing of Internet connections as a wired/wireless hotspot

And Much More Features are there....

Monday 11 November 2013

Android : Version History

Android Version History

Version of Android since 1.5 has been developed with a specific codename. These codenames are chosen alphabetically, and have thus far all been dessert items (or, generically, sweet/sugary foods). Some codenames are associated with more than one version number, while others are limited to only a specific one, and the reason for this inconsistency is not currently known. The naming typically appears to correspond to changes in the developer API levels, but this is not always true (example: 3.0 and 3.1 are both "Honeycomb" but they have different API levels).
The following names are used for the currently existing Android releases. Note that versions 1.0 and 1.1 were not publicly named. However, Android 1.1 was internally referred to as "Petit-Four

Cupcake:
•    Android 1.5

Donut:
•    Android 1.6

Eclair:
•    Android 2.0
•    Android 2.1

Froyo: (short for "frozen yogurt")
•    Android 2.2

Gingerbread:
•    Android 2.3

Honeycomb:
•    Android 3.0
•    Android 3.1
•    Android 3.2

Ice Cream Sandwich:
•    Android 4.0

Jelly Bean:
•    Android 4.1
•    Android 4.2
•    Android 4.3

KitKat:
•    Android 4.4



Friday 8 November 2013

Android : Create New Folder in External Storage Directly.

In this tutorial we will create folder directly in external directory or at root.
follow Below steps.

1. Create New Android Application Project. Name it as RootFolder.
2. Open Your MainActivity.java file.
3. Replace your MainActivity.java code with below code.

MainActivity.java


package arshad.rootfolder;

import java.io.File;

import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

                @Override
                protected void onCreate(Bundle savedInstanceState) {
                                super.onCreate(savedInstanceState);
                                setContentView(R.layout.activity_main);
                               
                                 String newFolder = "/arshad";//folder name
                                    String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
                                    File myNewFolder = new File(extStorageDirectory + newFolder);
                                    myNewFolder.mkdir();
                }

                @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;
                }

}

4. Now Replace Below Code With your AndroidMenifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="arshad.rootfolder"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="arshad.rootfolder.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
 
5. Now Compile And Run Your Project. 
check your your external directory to new folder created or not.

To create new folder in external storage you may use below code anywhere you want.

 String newFolder = "/arshad";//folder name
                                    String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
                                    File myNewFolder = new File(extStorageDirectory + newFolder);
                                    myNewFolder.mkdir();

to take permission add this line to your AndroidMenifest.xml

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

All The Best :)



Tuesday 5 November 2013

Android : Vibrate On Click

In This Tutorial we will lwarn how to vibrate device on buttons click.

Follow Below Steps

1. Create New Android Project Name it as vibrate.


2 . After Creating New Project , Open Your activity_main.xml. Follow Path .res --> Layout --> activity_main.xml.
3 . Add Below Code to your activity_main.xml.

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=".MainActivity" >

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

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="72dp"
        android:text="Vibrate" />

</RelativeLayout>


4 . Add Below Code To your MainActivity.java

MainActivity.java


package arshad.vibrate;

import android.os.Bundle;
import android.os.Vibrator;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {
Button vib;

       @Override
       protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              vib=(Button)findViewById(R.id.button1);
             
              vib.setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View view) {      
                            final Vibrator vibe = (Vibrator) MainActivity.this.getSystemService(Context.VIBRATOR_SERVICE);
                               vibe.vibrate(80); 
//80 represents the milliseconds (the duration of the vibration)
               
                          }
                      });
       }

       @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;
       }

}


5. Now Compile And Run Your Project.

6. My Output Screen is as below


All The Best :)