Thursday, 18 December 2014

Android Complete Video Tutorials Started

Here are the first 3 parts

About Andorid Tutorils : https://www.youtube.com/watch?v=Be5_MLB9rV4

Introduction to Android Part - 1 : https://www.youtube.com/watch?v=Am3fZ5YkTMo

Introduction to Android Part - 2 : https://www.youtube.com/watch?v=puAP7CEtjM0

Adroid Studio Installation Setup : https://www.youtube.com/watch?v=L3s_3T9z1k4

No Wallpaper Google Play application

By using this application you can save some battery power. Try this app give me rating.

download here : https://play.google.com/store/apps/details?id=com.ram.nowallpaperbackground

Tuesday, 9 December 2014

Creating AVD (Emulator) in Android Studio

You can create AVD in Android Studio by following below procedure:

First in Android Studio select Android Device Monitor short cut icon as shown below.

In next window select Android Virtual device manage short cur icon as shown below.


in next window select create option as follows.


in next window give emulator information as show below and finally hit ok button to create AVD.



AVD creaated created successfully after hitting ok button as follows.


Next you can launch the AVD by select the avd in the list and click start button in right side as shown below


Finally your new AVD with Android 5.0 lollipop version looks like as follows.


Android Studio Installation Setup Procedure

System Requirements:


Windows

  • Microsoft Windows 8/7/Vista/2003 (32 or 64-bit)
  • 2 GB RAM minimum, 4 GB RAM recommended
  • 400 MB hard disk space + at least 1 G for Android SDK, emulator system images, and caches
  • 1280 x 800 minimum screen resolution
  • Java Development Kit (JDK) 7
  • Optional for accelerated emulator: Intel processor with support for Intel VT-x, Intel EM64T (Intel 64), and Execute Disable (XD) Bit functionality
Mac OS X 
  • Mac OS X 10.8.5 or higher, up to 10.9 (Mavericks)
  • 2 GB RAM minimum, 4 GB RAM recommended
  • 400 MB hard disk space
  • At least 1 GB for Android SDK, emulator system images, and caches
  • 1280 x 800 minimum screen resolution
  • Java Runtime Environment (JRE) 6
  • Java Development Kit (JDK) 7
  • Optional for accelerated emulator: Intel processor with support for Intel VT-x, Intel EM64T (Intel 64), and Execute Disable (XD) Bit functionality
On Mac OS, run Android Studio with Java Runtime Environment (JRE) 6 for optimized font rendering. You can then configure your project to use Java Development Kit (JDK) 6 or JDK 7.

Linux
  • GNOME or KDE desktop
  • GNU C Library (glibc) 2.11 or later
  • 2 GB RAM minimum, 4 GB RAM recommended
  • 400 MB hard disk space
  • At least 1 GB for Android SDK, emulator system images, and caches
  • 1280 x 800 minimum screen resolution
  • Oracle Java Development Kit (JDK) 7
First intstall JDK 7 or above version in any operating system as mentioned above . And if it is asking path setup the path .

Downloading Android Studio 

You can download Android Studio from this link : http://developer.android.com/sdk/index.html#Requirements

Android Studio will be download with .exe extension so just you need to double click on the file and continue with on Screen instructions. 

To complete Installation it will take several minutes.

Once Setup has been completed you can start Android studio from programs.

After starting Android Studio it will be looks like below. And from below window select the option
Start a new Android Studio project as shown below

In next window select minimun android sdk version  and hit next button as shown below


In next window select Template as Blank Activity and hit next button as shown below.



In next window just hit finish button and your Android Studio IDE will be open for the created project development and in that IDE just left side you can see project button just hit that project explorer will be open as show below



 Next you need to download important packages from SDK Manager to run android application and to create Android Virtual Device .

Follow the below steps to download necessary packages from SDK Manager.

From Android Studio select Android SDK Manager short cut it will open SDK manager as follows.
Next select the packages and install them as follows.



After installing packages you can create Android Virtual Device .

Procedure to create AVD you can read in my next post .here is the link http://ramsandroid4all.blogspot.in/2014/12/creating-avd-emulator-in-android-studio.html

Migrating to Android Studio

If you have been using Eclipse with ADT, be aware that Android Studio is now the official IDE for Android, so you should migrate to Android Studio to receive all the latest IDE updates.

To migrate existing Android projects, simply import them using Android Studio:

1.In Android Studio, close any projects currently open. You should see the Welcome to Android Studio window.

2.Click Import Non-Android Studio project.

3.Locate the project you exported from Eclipse, expand it, select the build.gradle file and click OK.

4.In the following dialog, leave Use gradle wrapper selected and click OK. (You do not need to specify the Gradle home.)

Android Studio properly updates the project structure and creates the appropriate Gradle build file.

The official Android IDE anounced : Android Studio

Google recently anounced Android Studio is thier official Android IDE check this official link to get more information .
http://developer.android.com/sdk/index.html

Passing data between Activities using Bundle class in Android video tutorial

Passing Data between Activities using Intent Class in Android Video Tutorial.

Tuesday, 2 December 2014

Location Profile Automatic App on Google Play

Hi to all my blog followers,

Here i'm giving the link of my latest app on google play called Location Profile Automatic.

Try my application and give me rating and comments to improve this application.

app link : https://play.google.com/store/apps/details?id=com.ram.locationupdates

Friday, 7 November 2014

Rotating View in Layout in Android

We can rotate any view in layout from default to any angle .

For example below ImageView in layout before rotating like as follows.
xml code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.ram.viewrotate.MainActivity"
    tools:ignore="MergeRootFrame" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/ic_launcher"
      />
</RelativeLayout>



If you want to rotate just add rotate property to the view for example i have added to imageview After adding rotation property view  looks like as follows
xml code:
   <ImageView
        android:id="@+id/imageView1"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/ic_launcher"
        android:rotation="90"/>



Wednesday, 24 September 2014

ContextMenu with Header in Android


Download project here : ContextMenuwithHeader.zip

for context menu options create menu.xml file under menu folder under res folder
 menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/item_option1"
        android:title="Option1">
    </item>
    <item
        android:id="@+id/item_option2"
        android:title="Option2">
    </item>
    <item
        android:id="@+id/item_option3"
        android:title="Option3">
    </item>
    <item
        android:id="@+id/item_option4"
        android:title="Option4">
    </item>
    <item
        android:id="@+id/item_option5"
        android:title="Option5">
    </item>

</menu>


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"
    tools:context="${packageName}.${activityClass}" >

    <Button
        android:id="@+id/button_longPress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="144dp"
        android:text="Long press here" />

</RelativeLayout>


MainActivity.java:
package com.ram.customcontextmenu;

import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity
{

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

        // Calling button reference from xml layout
        Button contextMenu_button = (Button) findViewById(R.id.button_longPress);

        // registering button for the context menu
        registerForContextMenu(contextMenu_button);
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
    {
        super.onCreateContextMenu(menu, v, menuInfo);
        // setting header title for the context menu
        menu.setHeaderTitle("Select an Option");
        // Setting header icon
        menu.setHeaderIcon(R.drawable.ic_launcher);
        // Inflating menu.xml file from menu folder
        getMenuInflater().inflate(R.menu.menu, menu);
    }

    @Override
    public boolean onContextItemSelected(MenuItem item)
    {
        // To listen action for the context menu options
        switch (item.getItemId())
        {
        case R.id.item_option1:
            Toast.makeText(getApplicationContext(), "option1 selected",
                    Toast.LENGTH_SHORT).show();
            break;

        case R.id.item_option2:
            Toast.makeText(getApplicationContext(), "option2 selected",
                    Toast.LENGTH_SHORT).show();
            break;

        case R.id.item_option3:
            Toast.makeText(getApplicationContext(), "option3 selected",
                    Toast.LENGTH_SHORT).show();
            break;

        case R.id.item_option4:
            Toast.makeText(getApplicationContext(), "option4 selected",
                    Toast.LENGTH_SHORT).show();
            break;

        case R.id.item_option5:
            Toast.makeText(getApplicationContext(), "option5 selected",
                    Toast.LENGTH_SHORT).show();
            break;
        }
        return super.onContextItemSelected(item);

    }
}
 

Sunday, 21 September 2014

Android Fresher Openings

Android Fresher Openings

Number of openings : 5

Location : Hyderabad

Candidate should have strong knowledge in Android.

Send you resumes to : rambabu.mareedu@gmail.com

visit : http://ramsandroid4all.blogspot.in/

Thursday, 18 September 2014

Loading Image from Gallery example in Android

First of all create some string values in strings.xml as follows
strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Loading Images From Gallery</string>
    <string name="hello_world">Hello world!</string>
    <string name="load_image_button_text">Load Image From Gallery</string>
    <string name="image">image</string>


</resources>


Next create one button and image as follows
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"
    tools:context="${relativePackage}.${activityClass}" >

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="loadImageFromGallery"
        android:text="@string/load_image_button_text" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="@string/image"
        android:src="@drawable/ic_launcher" />

</LinearLayout>


MainActivity.java:
package com.ram.loadingimagesfromgallery;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends Activity
{
    // ImgeView to display image from gallery
    ImageView imageView;
    // variable to hold request code value
    private final int REQ_CODE = 1;

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

        // Initializing user interface from activity_main.xml file
        imageView = (ImageView) findViewById(R.id.imageView);
    }

    // Method to listen action for the button
    public void loadImageFromGallery(View view)
    {
        // Intent to mention which kind of action to be performed
        Intent intent = new Intent(Intent.ACTION_PICK,
                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

        // To launch intent
        startActivityForResult(intent, REQ_CODE);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == REQ_CODE && resultCode == RESULT_OK && data != null)
        {
            // Retrieve data this intent is operating on
            Uri selectedImage = data.getData();
            // The Media provider contains meta data for all available media on
            // both internal and external storage devices.

            String[] filePathColumn =
            { MediaStore.Images.Media.DATA };
            // Query the given URI, returning a Cursor over the result set.
            Cursor cursor = getContentResolver().query(selectedImage, filePathColumn,
                    null, null, null);
            // Move the cursor to the first row.
            cursor.moveToFirst();
            // To get given column index number
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            // Returns the value of the requested column as a String.
            String picturePath = cursor.getString(columnIndex);
            // Closes the Cursor, releasing all of its resources and making it
            // completely invalid. Unlike deactivate() a call to requery() will
            // not make the Cursor valid again.

            cursor.close();
            // Sets a Bitmap as the content of this ImageView.
            imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));

        }

    }
}

Wednesday, 17 September 2014

Converting Bitmap to Byte Array in Android

public byte[] convertBitmapToByteArray(Bitmap bitmap)
    {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();

        bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);

        byte[] bitmapData = stream.toByteArray();

        return bitmapData;
    }

Converting Byte Array to Bitmap in Android

public Bitmap ByteArrayToBitmap(byte[] byteArray)
    {
        ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(byteArray);
        Bitmap bitmap = BitmapFactory.decodeStream(arrayInputStream);
        return bitmap;
    }

Tuesday, 2 September 2014

Transparent Live Wallpaper Application

Hi viewers ,

I have developed Transparent Live Wallpaper application. You can give a try to this app and give your valuable Rating and Feedback .

Yours,
ramsandroid4all.

you can download this app by clicking the link below
 https://play.google.com/store/apps/details?id=com.ram.transparentlivewallpaper

Mirror Live Wallpaper Android Application

Hi viewers ,

I have developed Mirror Live Wallpaper application. You can give a try to this app and give your valuable Rating and Feedback .

Yours,
ramsandroid4all.

you can download this app by clicking the link below
https://play.google.com/store/apps/details?id=com.ram.w

Thursday, 21 August 2014

Android Tutorial Android Application updated version released today.

Here i am sharing the link of my Android Tutorial application.

From past few years i am maintaining this blog to help others who are learning android and who are already in the development .

So here my kind request is please download this application and give me rating and comments so that i can help people through this android tutorial application .

you can download  by clicking this here : Android Tutorial Application

Thanks,
yours Ram

Wednesday, 13 August 2014

Facebook SDK Integration in Android Tutorial Part 3 (Post status to Facebook and Share image to Facebook )

Download this project-->SampleFIntegration.zip

strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">SampleFBIntegration</string>
    <string name="hello_world">Hello world!</string>
    <string name="app_id">739274269466534</string>

</resources>

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

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".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>

        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/app_id" />

        <activity android:name="com.facebook.LoginActivity" />
    </application>

</manifest>

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"
    tools:context="${relativePackage}.${activityClass}" >

    <Button
        android:id="@+id/button_login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:text="Login" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button_login"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:text="Welcome"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <Button
        android:id="@+id/button_postStatus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:text="Post Status" />

    

    <Button
        android:id="@+id/button_postImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/button_postStatus"
        android:layout_below="@+id/button_postStatus"
        android:layout_marginTop="20dp"
        android:text="Post Image" />

</RelativeLayout>

MainActivity.java:
package com.ram.samplefintegration;

import java.util.Arrays;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.UiLifecycleHelper;
import com.facebook.model.GraphUser;

public class MainActivity extends Activity implements OnClickListener
{
    Button loginButton, postStatusButton;
    Button postImageButton;
    TextView text;
    private static final List<String> PERMISSIONS = Arrays.asList("publish_actions");
    private UiLifecycleHelper uiHelper;
    Session fSession;

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

        uiHelper = new UiLifecycleHelper(this, statusCallback);
        uiHelper.onCreate(savedInstanceState);

        text = (TextView) findViewById(R.id.textView);
        loginButton = (Button) findViewById(R.id.button_login);
        postStatusButton = (Button) findViewById(R.id.button_postStatus);
        postImageButton = (Button) findViewById(R.id.button_postImage);

        postImageButton.setOnClickListener(this);
        loginButton.setOnClickListener(this);
        postStatusButton.setOnClickListener(this);

        if (Session.getActiveSession().isOpened())
        {
            Session.openActiveSession(this, true, statusCallback);
            loginButton.setEnabled(false);
        } else
        {
            buttonsDisable();
        }

    }

    @Override
    public void onClick(View v)
    {
        switch (v.getId())
        {
        case R.id.button_login:
            // start facebook login
            Session.openActiveSession(this, true, statusCallback);
            break;

        case R.id.button_postStatus:
            // To post status to facebook
            postStatusMessage("Hi to all....Sample status shared from android app");
            break;

        case R.id.button_postImage:
            postImage();
            break;
        }

    }

    Session.StatusCallback statusCallback = new Session.StatusCallback()
    {
        @Override
        public void call(Session session, SessionState state, Exception exception)
        {
            if (state.isOpened())
            {
                fSession = session;
                getUserProfie();
            } else
            {
                buttonsDisable();
            }
        }
    };

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        super.onActivityResult(requestCode, resultCode, data);
        uiHelper.onActivityResult(requestCode, resultCode, data);
        Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
    }

    public void postStatusMessage(String message)
    {
        if (checkPermissions())
        {
            Request request = Request.newStatusUpdateRequest(fSession, message,
                    new Request.Callback()
                    {
                        @Override
                        public void onCompleted(Response response)
                        {
                            if (response.getError() == null)
                                Toast.makeText(MainActivity.this,
                                        "Status updated successfully", Toast.LENGTH_LONG)
                                        .show();
                        }
                    });
            request.executeAsync();
        } else
        {
            requestPermissions();
        }
    }

    void getUserProfie()
    {
        // make request to the /me API to get user details
        Request.newMeRequest(fSession, new Request.GraphUserCallback()
        {

            // callback after Graph API response with user
            // object
            @Override
            public void onCompleted(GraphUser user, Response response)
            {
                if (user != null)
                {
                    // To display facebook user name of the user
                    text.setText("Hello " + user.getName() + "!");

                    buttonsEnable();
                }
            }
        }).executeAsync();
    }

    public void postImage()
    {
        if (checkPermissions())
        {
            Bitmap img = BitmapFactory.decodeResource(getResources(),
                    R.drawable.ic_launcher);

            Request uploadRequest = Request.newUploadPhotoRequest(
                    Session.getActiveSession(), img, new Request.Callback()
                    {
                        @Override
                        public void onCompleted(Response response)
                        {
                            Toast.makeText(MainActivity.this,
                                    "Photo uploaded successfully", Toast.LENGTH_LONG)
                                    .show();
                        }
                    });
            uploadRequest.executeAsync();
        } else
        {
            requestPermissions();
        }
    }

    public void requestPermissions()
    {
        Session s = Session.getActiveSession();
        if (s != null)
            s.requestNewPublishPermissions(new Session.NewPermissionsRequest(this,
                    PERMISSIONS));
    }

    public boolean checkPermissions()
    {
        Session s = Session.getActiveSession();
        if (s != null)
        {
            return s.getPermissions().contains("publish_actions");
        } else
            return false;
    }

    @Override
    public void onSaveInstanceState(Bundle savedState)
    {
        super.onSaveInstanceState(savedState);
        uiHelper.onSaveInstanceState(savedState);
    }

    @Override
    public void onResume()
    {
        super.onResume();
        uiHelper.onResume();

    }

    @Override
    public void onPause()
    {
        super.onPause();
        uiHelper.onPause();
    }

    @Override
    public void onDestroy()
    {
        super.onDestroy();
        uiHelper.onDestroy();
    }

    void buttonsEnable()
    {
        loginButton.setEnabled(false);
        postStatusButton.setEnabled(true);
        postImageButton.setEnabled(true);
    }

    void buttonsDisable()
    {
        postStatusButton.setEnabled(false);
        postImageButton.setEnabled(false);
        loginButton.setEnabled(true);
    }
}

ScreenShot:




Monday, 11 August 2014

Facebook SDK Integration in Android Tutorial Part 2 (Sign in with facebook)

To add an option call sign in with facebook we need to follow following procedure:

First we need to add facebook app id to our project.
-->To add the Facebook app ID into your project, open up the strings.xml file in the res/values folder of your project. we need to add an app_id string containing the ID that we obtained  from the https://developers.facebook.com website . To know how to create facebook app id you can read part1.

strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">SampleFBIntegration</string>
    <string name="hello_world">Hello world!</string>
    <string name="app_id">739274269466534</string>

</resources>


Next add Internet permission , meta data tag and Activity in AndroidManifest.xml as follows:

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

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".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>

        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/app_id" />


        <activity android:name="com.facebook.LoginActivity" />
    </application>

</manifest>


Next create login button and one TextView in xml  layout as follows:

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"
    tools:context="${relativePackage}.${activityClass}" >

    <Button
        android:id="@+id/button_login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="21dp"
        android:text="Login" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/button_login"
        android:layout_marginTop="27dp"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>





Next add following java code in Activity as follows:
MainActivity.java:
package com.ram.samplefintegration;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.Session.StatusCallback;
import com.facebook.SessionState;
import com.facebook.model.GraphUser;

public class MainActivity extends Activity implements OnClickListener
{
    Button loginButton;
    TextView text;

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

        text = (TextView) findViewById(R.id.textView);
        loginButton = (Button) findViewById(R.id.button_login);
        loginButton.setOnClickListener(this);

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        super.onActivityResult(requestCode, resultCode, data);
        Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
    }

    @Override
    public void onClick(View v)
    {
        // start facebook login
        Session.openActiveSession(this, true, new StatusCallback()
        {
            // callback when session changes state
            @Override
            public void call(Session session, SessionState state, Exception exception)
            {
                if (session.isOpened())
                {
                    // make request to the /me API to get user details
                    Request.newMeRequest(session, new Request.GraphUserCallback()
                    {

                        // callback after Graph API response with user
                        // object
                        @Override
                        public void onCompleted(GraphUser user, Response response)
                        {
                            if (user != null)
                            {
                                // To display facebook user name of the user
                                text.setText("Hello " + user.getName() + "!");
                            }
                        }
                    }).executeAsync();
                }

            }
        });

    }
}







Output Screen Shots:







Tuesday, 29 July 2014

Facebook SDK Integration in Android Tutorial Part 1

First of all we need to Sign in into https://developers.facebook.com/  website .

After Sign in we need to select Create a New App option under Apps drop down menu as follows

After selecting Create a New App option we will get Create a New App window .

In this window we can see two input fields called Display Name and Name Space
we need to enter only our application name in Display Name field
and we can leave Name Space field empty.
Next choose Category that our application belongs to and then finally click Create App button to finish. 
 Once select Create App button in next window we can see application dashboard as follows.
and in this dashboard only we can get our application id and App Secret

 Next step is in this dashboard we need select Settings option from left side navigation bar as follows

Next we need to select  +Add Platform option as follows

After selecting Add Platform option we will get Select Platform window there we need to select Android platform as follows.

In the next window please provide the application package name and key hashes and select single sign on option and then finally select save changes button as shown in below

Note: to generate key hash for your application please read this post in my blog
http://ramsandroid4all.blogspot.in/2014/07/generating-facebook-key-hash.html


Next download android facebook sdk from here : https://developers.facebook.com/docs/android/downloads

after download we will get facebook sdk zip file just extract it.
Next import facebook sdk into Eclipse as follows
1.under package explorer right click and select import option.
2.next under android folder select Existing Projects into Workspace option.
3.Next select root directory option and browse facebook sdk folder.
4.once we browse android sdk folder it will show you number projects and can import them all
   and you can run them as sample facebook projects or you can just select facebook sdk project and
   hit finish button


Next we need to add facebook sdk library to our project to that follow below steps:
1.Right click on the our project and select properties option
2.In the next window select android
3.under library select add option next it will show you facebook sdk select it and select apply button  
   and select ok button . as shown in below