Posts Tagged ‘Android’

Drag to connect!

Posted: April 1, 2017 in Android, Technology
Tags: , , , , ,

Hello Droids,

Connecting app with social media or connect to app with social media is great thing which we have seen in many apps.

Login with FB, Twitter, Google etc.. what we have seen is a button with icon and text waiting for a tap on it to do the rest things. (How boring! )

Lets add some UX to the social media connectivity 🙂



Checkout the code snippet from here :

Implementation of this code will make your login screen more attractive.


Hope you will like this post.

Conceptualized by :

Thanks 🙂

Keep Coding!

Hello all,

After getting so many +1 over stackoverflow for my answer on the question : How to use RecyclerView inside NestedScrollView?

You can add RecyclerView without adding it into NestedScrollView. How? Here is the trick:

 xmlns:tools="" android:layout_width="match_parent"
 android:layout_height="match_parent" android:fitsSystemWindows="true">

< android:layout_height="wrap_content"
 android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">

 app:popupTheme="@style/AppTheme.PopupOverlay" />

 android:layout_height="wrap_content" />

The key thing here is :


Have fun! Keep Coding!

This slideshow requires JavaScript.

Calendar Clock combination in DayDream!

Get it on Google Play

Waiting for your Comments and Response.

Hello Droids,

As we all aware about RPC (Remote Procedure Call) in Java, right?

Lets do the same thing in Android, different name same functioning in way better 🙂
AIDL (Android Interface Definition Language)

Here I’m going to provide you step by step guidance for implementing AIDL in android.

Let’s Start a new project and named it as your favorite one for this demo.

  • Create on .aidl extension file, actually it is interface file so name it as IRemoteService.aidl
  • After creating this file add signature method in this file as follow,
// Declare the interface

interface IStringOperations {
    // You can pass values in, out, or inout.
    // Primitive datatypes (such as int, boolean, etc.) can only be passed in.
    String concat(in String value1, in String value2);
  • Now, create one Java file into the same package and extends it to Service.


public class StringOperations extends Service{

	public void onCreate() {

	public IBinder onBind(Intent intent) {

		return mBinder;

	 * @author Rahul Upadhyay
	private final IStringOperations.Stub mBinder = new IStringOperations.Stub() {
		 * Signature method which was declared in .aidl file will be coded here
		 * @author Rahul Upadhyay
		public String concat(String value1, String value2) throws RemoteException {
			return value1+ " "+ value2;

  • Now, create a client which will connect to this service with help of ServiceConnection, establishing ServiceConnection
* @author Rahul Upadhyay
* ServiceConnection clsss to connect the service.
	private ServiceConnection mServiceConnection = new ServiceConnection() {

		public void onServiceDisconnected(ComponentName name) {

			// Set null to service to unbind the object
			service = null;
			Log.d(TAG, "onServiceConnected() disconnected");

		public void onServiceConnected(ComponentName name, IBinder boundService) {

			//allocate the service to the interface
			service = IStringOperations.Stub.asInterface(boundService);
			Log.d(TAG, "onServiceConnected() connected");

  • Bind the service,
* bindService will call the onServiceConnected method which will bind the Service with the current activity
		boolean ret = bindService(new Intent(this, StringOperations.class),
				mServiceConnection, Context.BIND_AUTO_CREATE);

		Log.d(TAG, "initService() bound with " + ret);
    use the Service method which is declared in .aidl
service.concat("Rahul ", "Upadhyay")

Download the example from here

Hello Droids,

As we get error in applying Facebook SSO (Single Sign On ) feature in app, stating that,

“your application is miss-configured..” the problem is in generating the Hash key.

So lets generate the hash key from the application not from the console and use that hash key in Facebook app, which will configure your app with Facebook SSO 🙂

here is the code for that,

* Add this code to print out the key hash, and use that KeyHash
 try {
      PackageInfo info = getPackageManager().getPackageInfo(
      "com.myapp", PackageManager.GET_SIGNATURES);
      for (Signature signature : info.signatures) {
          MessageDigest md = MessageDigest.getInstance("SHA");
          Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
} catch (NameNotFoundException e) {

} catch (NoSuchAlgorithmException e) {


We are about to implement MAP API2 in our project, here its Glimpse,


  1.  do login here,
  2.  on left side panel click on “Services”
  3.  find the service “Google Maps Android API v2” turn it on. Accept the terms and condition.
  4.  Now go back and click on “API Access”
  5.  Click on “Create new Android Key”
  6.  Paste SHA1 fingerprint there.

e.g., 9A:3D:9C:57:B6:46:E2:1C:EC:CF:BD:D3:EA:A6:B7:81:27:49:69:1A;com.example

here com.example – its an application package name

a. what is SHA1 key here?
Its a android debug keystore, where android app is Developed. when Signed APK is generated, this SHA1 will be regenerate using new keystore of application.
b. how to generate that?
open command prompt, and then

C:\Program Files\Java\jdk1.6.0_20\bin>keytool -list -v -keystore “c:\Users\admin\.android\debug.keystore”

you will prompt for password, enter “android” without qoute
It will give you the rtesult like this,

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 1 entry

Alias name: androiddebugkey
Creation date: Nov 5, 2012
Entry type: PrivateKeyEntry
Certificate chain length: 1
Owner: CN=Android Debug, O=Android, C=US
Issuer: CN=Android Debug, O=Android, C=US
Serial number: 50975212
Valid from: Mon Nov 05 11:13:46 IST 2012 until: Wed Oct 29 11:13:46 IST 2042

Certificate fingerprints:
MD5: BD:30:DD:77:0F:BE:82:A1:20:59:46:28:E7:11:E2:C8
SHA1: 9A:3D:9C:57:B6:46:E2:1C:EC:CF:BD:D3:EA:A6:B7:81:27:49:69:1A
Signature algorithm name: SHA1withRSA
Version: 3


C:\Program Files\Java\jdk1.6.0_20\bin>

this SHA1 is of my Computer local Keystore.

After generating new aandroid key,
it will be listed in your page, with Title saying “Key for Android apps (with certificates)”
You have to give me that API Key for implement MAP in application. It will look like “AIzaSyBmWleqdGClIWXXhgMbKAt-0aBxdohmmaM”

Then and then MAP can be loaded.

NOTE: If you are not getting this then please follow this link,

Now lets start code in Project,

create on layout file, map_activity.xml
and paste this code,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" >

        android:layout_height="match_parent" >


Now, create one Class file in your project,

Code it like this,

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;

import com.example.R;

public class MapActivity extends Activity {

	private final String tag = getClass().getName();

	private GoogleMap googleMap;
	private Double lat, lon;
	private LatLng latLng;

	protected void onCreate(Bundle arg0) {

	*provide lat long
			lat =  gpsLocationTracker.getLatitude();
			lon =  gpsLocationTracker.getLongitude();

	        latLng = new LatLng(lat, lon);
	        try {

	        	googleMap = ((MapFragment)getFragmentManager().findFragmentById(;
				CameraPosition cp = new CameraPosition.Builder()
				.target(new LatLng(lat,lon))

				/*adding custom marker on the map*/
				googleMap.addMarker(new MarkerOptions()
						.title("My First Marker")
			} catch (Exception e) {
				// TODO Auto-generated catch block



Now, in AndroidManifest.xml

        android:targetSdkVersion="16" />

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

    <!-- MAP API V2 -->
        android:protectionLevel="signature" />

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

    <!-- MAP API V2 -->
        android:required="true" />

now inside Application tag

<!-- MAP Api V2 -->
<!-- Place your ANDROID API KEY for MAP at res/string/mapv2 -->
            android:value="@string/mapv2" />
<activity android:name="com.plunder.utility.MapActivity" >

NOTE: Don’t forget to include Library project, you can find it here

WebResponce in Android

Posted: July 31, 2012 in Android
Tags: , ,

Hello Droids..!

Here i am demonstrating a class file which will be very helpful in getting web-response. I read so many comments on Web-Response that giving error in fetching.

So here is the .java file into which you just have to pass the URL! and in response you will get String value! That’s it!  Easy and handy!

Here is the Code,

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

public class WebResponse {

	public String getWebResponse(String URL)
	  HttpClient httpclient = new DefaultHttpClient();
      HttpResponse response;
     String responseString = "";
      try {

//           String temp = URL;
//              temp = temp.replaceAll(" ","%20");

          response = httpclient.execute(new HttpGet(URL));
          StatusLine statusLine = response.getStatusLine();
          if(statusLine.getStatusCode() == HttpStatus.SC_OK){
              ByteArrayOutputStream out = new ByteArrayOutputStream();
              responseString = out.toString();

          } else{
              //Closes the connection.
              throw new IOException(statusLine.getReasonPhrase());
      } catch (ClientProtocolException e) {
          //TODO Handle problems..

      } catch (IOException e) {
          //TODO Handle problems..
      return responseString;


How to use:

//first create an object of this class file
WebResponse wr = new WebResponse();
String resp = wr.getWebResponse(your url); //add your url

Download here::

Comments will be appreciated. 🙂

This is a sample app for integrating Facebook in android.

This will show you how to manage session(is session expired or not), how to handle it.

You are able to post on your own wall, with Title, Message, Link of app, Image and Properties of particular app.

You just have to provide your Facebook app id.

Here is the source code, Android Facebook Demo

Toggle on/off GPS in Android

Posted: June 3, 2012 in Android
Tags: ,

Hello folks, here am again with android simple code of GPS toggle on/off from code.
what you have to do is just copy the following code in (where you set your global variables and functions)

when you need to turn on GPS, just call Global.turnGPSOn(“your context”)

here, “your context” will be the class file from where you are calling this function,
let say, i have a class file, named “” so what i have to pass as a parameter in that function is,

you can also use, getApplicationContext() as a parameter. But I recommend to use class file name.

Now here is the code,

public static void turnGPSOn(Context context){
        String provider = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

{ //if gps is disabled
            final Intent poke = new Intent();
            poke.setClassName("", ""); 
    public static void turnGPSOff(Context context){
        String provider = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

            final Intent poke = new Intent();
            poke.setClassName("", ""); 

we heard and face so many times that our phone battery is drawn and all that, its due to constant pinging of GPS from any application, which will cause the battery issues. So when you need to fetch location from GPS provider, just turn on the GPS from code and after using it, turn off it.