www.androidchunk.com

Hi Developer, Please visit www.androidchunk.com for Latest Updates. Thank you!

How to set AdMob Banner In Navigation Drawer ?

Category: Android Codez | Last Updates: 09/08/2017

In this section we are going to set AdMob banner Ad in Navigation Drawer.

Create New project 
Create New project with Navigation Drawer Activity in Android Studio.

Android Studio>>Navigation Drawer Activity>>Finish

AdMob AppId & AdUnitId
If you already have AdMob account then sign in and get App Id & AdUnitId (banner). Otherwise, create a new account and take the next steps. Or if you wish to just test this then the test app id and adUnitId provided below. Use it. You can grab more sample test ids from the official developer website



Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713

Sample Banner ad unit ID: ca-app-pub-3940256099942544/6300978111



Attention, App Id & AdUnitId are two different things. Do not get confused about it.

Import the Google Mobile Ads
First of all we have to import the Google Mobile Ads SDK into our project to enable Google AdMob Ads. Import the Google Mobile Ads SDK in the app-level build.gradle.

app/build.gradle

Set Banner In Layout

layout/activity_main.xml

Initializing & Loading Banner Ad
Using initialize static method of the MobileAds class, Initialize the Google AdMob Ads. After that we have to create a reference object of AdView class to finding our banner adView.

src/MainActivity.java

Add Internet Permission
Please wait, Add Internet permission in the AndroidManifest.


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


Output


Happy Coding!

How to create Android Custom Notification

Category: Android Codez | Last Updates: 09/08/2017




Hi Android Developer, 
In this tutorial, We are going to learn about how to create Android Custom Notification. Notification is a kind of message that is displayed on the notification panel. Through notifications you can tell your user or system about an event or an error. By using this you can tell your user what is updating and/or happening inside your application! 
So why wait, let's get started.

Create New project 
Create New project with Empty Activity in Android Studio.

Android Studio>>Empty Activity>>Finish

Create A Layout File
To create a custom notification, We need to create a layout file. Create a layout file according to your need.

res/layout/custom_notification.xml
res/values/strings.xml
res/layout/activity_main.xml
Coding For Custom Notification

src/MainActivity.java
Okay, our Custom Notification is ready. Debug the app and share your experiences. happy coding!

Output

Simple Android Fragments Example In Android Studio

Category: Android Codez | Last Updates: 31/07/2017

Hey android developer, In this part We will know about Simple Android Fragment.
Let's see few points about Android Fragments:

Fragment
-has its own Layout
-has its own Behavior
-has its life cycle
-can be used in single as well as multiple activities
-used as part of the Activity

Now we are going to start creating simple android fragments.

Create New project: 
Create New project with Empty Activity in Android Studio.

Android Studio>>Empty Activity>>Finish

Create Fragments:
To create new blank fragment, We have made two simple fragments.
Android Studio>File>New>Fragment>Fragment (Blank)

res/layout/fragment_my_first.xml

src/MyFirstFragment.java
res/layout/fragment_my_second.xml

src/MySecondFragment.java

Define Fragment container:
We have to define a container in main activity's layout file. This container will hold our fragment. For setting (Adding/Removing) fragments, We have taken two buttons.

res/layout/activity_main.xml


Add/Remove Fragment in Activity:
By clicking the button from the MainActivity, We will set the fragment to fragment container.

src/MainActivity.java

res/values/strings.xml


Output:

How to create Bitmap blur effect in Android

Category: Android Codez | Last Updates: 31/05/2017



Hey Android developer, It's amazing and easy to create bitmap blur effect. Let's see how to do!

RenderScript Support Library
In this project We are going to use RenderScript Support Library. First of all let's learn something about the RenderScript.
  • RenderScript is a component of the Android operating system for mobile devices, that takes advantage of heterogeneous hardware to offer an API for performance acceleration. 
  • It allows developers to increase the performance of their applications at the cost of writing a greater amount of more complex code.
  • It provides the developer three primary tools:
    • A general purpose compute API across different system computing hardware
    • A compute API similar to CUDA, OpenCL or GLSL
    • A familiar C99-derived language
  • It can also be used for 3D graphics. Android 4.2 added new capabilities to script intrinsics, such as Blend and Blur; as well as ScriptGroups which allow you to chain together related RenderScript scripts and execute them with one call.
Using RenderScripts Support Library
In Android Studio Project Add the following configuration to project build.gradle
 defaultConfig {
        minSdkVersion 11
        targetSdkVersion 24


        //add this two lines
        renderscriptTargetApi 19
        renderscriptSupportModeEnabled true
    }


Okay! Now you are ready to use RenderScripts Support Library. Let's start....
I have created a separate java class for create blur effect.

src/BlurMaker.java

In our activity class,
ImageView imageView = (ImageView) findViewById(R.id.imageView);
Bitmap srcBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.my_img);

imageView.setImageBitmap(BlurMaker.createBlur(getApplicationContext(), srcBitmap, 7.5f));













RenderScripts  data from Wikipedia

Image Erasing with Android Canvas

Category: Android Codez | Last Updates: 25/05/2017



In this section We are going to erasing Image/Photo in the Android. 

First of all We change our image into bitmap after that we have to change that bitmap into a mutable bitmap.

Converting drawable resource file into bitmap
Bitmap rawBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.test_img);

Converting bitmap into mutable bitmap
sourceBitmap = Bitmap.createBitmap(rawBitmap.getWidth(), rawBitmap.getHeight(), Bitmap.Config.ARGB_8888);

We are using PorterDuff.Mode.DST_IN mode for our paint object , Please see below image which describe that what is the PorterDuff.Mode.DST_IN

destPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));


If you want to know more about PorterDuff.Mode click here.

src/MyCustomView.java 

src/MainActivity.java

To Download Source Code click here.

Video Tutorial with Output: