Tuesday, 2 September 2014

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






Monday, 28 July 2014

Generating Facebook Key Hash

package com.ram.facebookkeyhash;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import com.ram.demo1.R;
import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;

public class MainActivity extends Activity
{
    // Declare your application package name
    String packageName = "your application package name";

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

        try
        {
            // Overall information about the contents of a package. This
            // corresponds to all of the information collected from
            // AndroidManifest.xml.
            PackageInfo packageInfo = getPackageManager().getPackageInfo(packageName,
                    PackageManager.GET_SIGNATURES);

            // Array of all signatures read from the package file. This is only
            // filled in if the flag GET_SIGNATURES was set.
            for (Signature signature : packageInfo.signatures)
            {
                // The basic pattern to digest an InputStream
                MessageDigest md = MessageDigest.getInstance("SHA");
                // The basic pattern to digest an InputStream
                md.update(signature.toByteArray());
                // Prints key hash in logcat
                Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }

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

Tuesday, 22 July 2014

Share Intent Example

Sending Simple Data to Other Apps

Sending and receiving data between applications with intents is most commonly used for social sharing of content. Intents allow users to share information quickly and easily, using their favorite applications.

NOTE: The best way to add a share action item to an ActionBar is to use ShareActionProvider, which became available in API level 14. ShareActionProvider is discussed in the lesson about Adding an Easy Share Action.

Send Text Content
The most straightforward and common use of the ACTION_SEND action is sending text content from one activity to another. For example, the built-in Browser app can share the URL of the currently-displayed page as text with any application. This is useful for sharing an article or website with friends via email or social networking. Here is the code to implement this type of sharing:

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);

If there's an installed application with a filter that matches ACTION_SEND and MIME type text/plain, the Android system will run it; if more than one application matches, the system displays a disambiguation dialog (a "chooser") that allows the user to choose an app. 

 However, if you call Intent.createChooser(), passing it your Intent object, it returns a version of your intent that will always display the chooser. This has some advantages:

  • Even if the user has previously selected a default action for this intent, the chooser will still be displayed.
  • If no applications match, Android displays a system message.
  • You can specify a title for the chooser dialog.

Example Application:
Screen Shots:



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/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="56dp"
        android:onClick="share"
        android:text="Share" />

</RelativeLayout>

MainActivity.java:
package com.ram.shareintent;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends Activity
{

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

    public void share(View view)
    {
        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
        sendIntent.setType("text/plain");
       startActivity(Intent.createChooser(sendIntent, "Share text to..."));
    }
}