Friday, November 17, 2017

Android Runtime permission

Welcome to this post.

In this post, I am going to discussing a new topic that is android runtime permission.

What is runtime permission?
Basically, when we want to access some data on the device or want to make a network request from our app, we need user permission.Basically, we need to write the permissions on the AndroidMenifest.xml
AndroidMenifest.xml

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
if the user installs the app, the user must accept the permissions that we write on AndroidMenifest.xml
But in Android 6.0 API 23
The Android team want to give more control to the user and now user can install without accepting all the permission.
For an example, we want to access to the storage(external storage), so we need permission first. Now we promote to the user to accept the permission in the app runtime to access the storage.
If the user does not accept the permission that means we do not access the storage.

Tuesday, November 14, 2017

Saturday, November 11, 2017

Android Settings Series (part 1)

Welcome to this Series post.
In this series post, we are going to create a complete Settings for a productive app.

Basic overview of our final settings?

Our final settings contains-
  •  multiple preference screen 
In a previous post, I  cover android settings with a single preference screen (Android App Settings with Preference Fragment Compat).

we create 3 screen that's are-
  • General
  • Backup 
  • Advance
So we create multiple preference screen in the same XML file and after user click, we replace the fragment.
That's the deal,
Lets Start-

Saturday, November 4, 2017

Google Chrome Custom Tab on your Android App

Welcome to this post.
In this post, we are going to learn how to use google chrome custom tab in our app.

In our app, we basically use webview for loading a web address. Or sometimes we make an intent that opens other browser and loads the web address.

But why we use Chrome custom tab?
Chrome custom tabs offer apps additional management over their internet expertise and build transitions between native and web content more seamless while not having to resort to a WebView.

Is any customization support? 
yes. Chrome custom tab supports some customization-

  • Toolbar color 
  • Enter and exit animations 
  • Add custom actions to the Chrome toolbar and overflow menu 

It also allows the developer to pre-start Chrome and pre-fetch content for faster loading.

Ok, Lets Start
First, add the below line in your build.gradle file
//chrome custom tab
compile 'com.android.support:customtabs:26.1.0'
Now create a method-
private void customTab(String url){
}
create a builder object
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
set toolbar color
builder.setToolbarColor(R.attr.colorPrimary);
set title is shown or not
builder.setShowTitle(false);
now build chrome custom intent
CustomTabsIntent customTabsIntent = builder.build();
now launch the URL
customTabsIntent.launchUrl(this, Uri.parse(url));
full code of this method
private void customTab(String url){
        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
        builder.setToolbarColor(R.attr.colorPrimary);
        builder.setShowTitle(false);
        // add share action to menu list
        builder.addDefaultShareMenuItem();
        CustomTabsIntent customTabsIntent = builder.build();
        customTabsIntent.launchUrl(this, Uri.parse(url));

    }
you can use this method anywhere. you just pass a web address.

Now make some customization- 
Menu:
add menu action button for default share action button
builder.addDefaultShareMenuItem();
want to custom share action button
builder.setActionButton(icon, description, pendingIntent, tint);
here, add a menu item
builder.addMenuItem(menuItemTitle, menuItemPendingIntent);

Animation:
add enter and exit animation
builder.setStartAnimations(this, R.anim.slide_in_right, R.anim.slide_out_left);
builder.setExitAnimations(this, R.anim.slide_in_left, R.anim.slide_out_right);
 that's it today post.
Want to customize more, then don't forget to check the official document of chrome custom tab

Thank you for reading this post.
Happy coding