Hello droids!

Here is another quick solution for not letting your app get crash in Nougat devices.

Mostly crash occurs with file permission while taking photo or selecting image from the gallery in Nougat devices.

In general you will get FileUriExposedException.

How to solve this issue?
Here is the quick solution, you need to follow 3 – 4 steps and voila you’re done!

Step 1 : provider_paths.xml
Create provider_paths.xml to /res/xml directory

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="external_files" path="."/>
</paths>

Step 2 : AndroidManifst file update
Open your manifest file and add below tags in between <application> </application> tags.

<provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="${applicationId}.provider"
    android:exported="false"
    android:grantUriPermissions="true">
<meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/provider_paths">
</provider>

 

Step 3 : Application class edit
Hope you are aware of how to declare application class. If not do comment on this post, I’ll let you know.

@Override
public void onCreate() {
    super.onCreate();
    //Allowing Strict mode policy for Nougat support
    StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
    StrictMode.setVmPolicy(builder.build());
}

Now, you are ready to access URI files from nougat enabled devices.
Don’t forget to add appropriate permissions to your manifest file for camera and external storage.

Have fun! Keep coding!

my_wallet

Image  —  Posted: May 27, 2016 in Technology

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:

<android.support.design.widget.CoordinatorLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
 android:layout_height="match_parent" android:fitsSystemWindows="true">

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

 <android.support.v7.widget.Toolbar
 android:layout_width="match_parent"
 android:layout_height="?attr/actionBarSize"
 android:background="?attr/colorPrimary"
 app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
 app:layout_behavior="@string/appbar_scrolling_view_behavior"
 android:layout_width="match_parent"
 android:layout_height="wrap_content" />
</android.support.design.widget.CoordinatorLayout>

The key thing here is :

 app:layout_behavior="@string/appbar_scrolling_view_behavior" 

Have fun! Keep Coding!

Now a days we are using Android Design Library to have rich look.

I’ve faced this problem while integrating RecyclerView with FAB (Floating Action Button) and I was not able to read the last line of it due to FAB was overlapping it.

I’ve tried this (Wrong assumption):


<android.support.v7.widget.RecyclerView 
android:id="@+id/my_recycler_view" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:padding_bottom="30dp"
/>

After some research found that its very easy to implement :

Method 1: Create Style

<style name="rvWithClipPadding">
<item name="android:clipToPadding">false</item>
<item name="android:paddingBottom">@dimen/margin_56dp</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:scrollbars">vertical</item>
</style>

use this style in xml,

<android.support.v7.widget.RecyclerView 
android:id="@+id/my_recycler_view" 
style="@style/rvWithClipPadding"
/>

Method 2: Use attributes while creating

<android.support.v7.widget.RecyclerView 
android:id="@+id/my_recycler_view" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:clipToPadding="false" 
android:paddingBottom="30dp" 
android:scrollbars="vertical"/>

 

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.

e.g.,

public class StringOperations extends Service{

	@Override
	public void onCreate() {
		super.onCreate();
	}

	@Override
	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() {

		@Override
		public void onServiceDisconnected(ComponentName name) {

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

		@Override
		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");
          md.update(signature.toByteArray());
          Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
      }
} catch (NameNotFoundException e) {

} catch (NoSuchAlgorithmException e) {

}