Tuesday 26 May 2015

Android Read Status Bar Notification | Android Read all incoming notification | Android Read Incoming Sms | Android Read Incoming Call

Hello Friends,
    Today, I am going to share a small tutorial on android "NotificationListenerService"
    which help us to read the all app notifications. This tutorial covers following


1. We can easily read the notification of other android application or read all status bar
2. Read|Listen incoming whatsapp messages
3. Read all incoming SMS
4. Read all incoming calls
5. Battery Low

Step1 : Create a Notification Service Class :
                    This class extends NotificationListenerService class which contains
                    two method:
                 a) onNotificationPosted(StatusBarNotification sbn) :
                           Implement this method to learn about new notifications as they are
                           posted by apps.
                 b) onNotificationRemoved(StatusBarNotification sbn) :
                           Implement this method to learn when notifications are removed.                         

 Note: The StatusBarNotifcation object contains extras, app package name and
            ticker name

1. NotificationService.java

package android.notifications;

import android.app.Notification;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.util.Log;
import android.support.v4.content.LocalBroadcastManager;

import java.io.ByteArrayOutputStream;

 * Created by mukesh on 19/5/15.
public class NotificationService extends NotificationListenerService {

    Context context;


    public void onCreate() {

        context = getApplicationContext();


    public void onNotificationPosted(StatusBarNotification sbn) {
        String pack = sbn.getPackageName();
        String ticker ="";
        if(sbn.getNotification().tickerText !=null) {
            ticker = sbn.getNotification().tickerText.toString();
        Bundle extras = sbn.getNotification().extras;
        String title = extras.getString("android.title");
        String text = extras.getCharSequence("android.text").toString();
        int id1 = extras.getInt(Notification.EXTRA_SMALL_ICON);
        Bitmap id = sbn.getNotification().largeIcon;


        Intent msgrcv = new Intent("Msg");
        msgrcv.putExtra("package", pack);
        msgrcv.putExtra("ticker", ticker);
        msgrcv.putExtra("title", title);
        msgrcv.putExtra("text", text);
        if(id != null) {
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            id.compress(Bitmap.CompressFormat.PNG, 100, stream);
            byte[] byteArray = stream.toByteArray();



    public void onNotificationRemoved(StatusBarNotification sbn) {
        Log.i("Msg","Notification Removed");



package android.notifications;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;

import java.util.ArrayList;

 * Created by mukesh on 19/5/15.
public class MainActivity extends Activity {

    ListView list;
    CustomListAdapter adapter;
    ArrayList modelList;

    protected void onCreate(Bundle savedInstanceState) {
        modelList = new ArrayList();
        adapter = new CustomListAdapter(getApplicationContext(), modelList);
        LocalBroadcastManager.getInstance(this).registerReceiver(onNotice, new IntentFilter("Msg"));

    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);//Menu Resource, Menu
        return true;

    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_settings:
                Intent intent = new Intent(
                return true;
                return super.onOptionsItemSelected(item);
    private BroadcastReceiver onNotice= new BroadcastReceiver() {

        public void onReceive(Context context, Intent intent) {
           // String pack = intent.getStringExtra("package");
            String title = intent.getStringExtra("title");
            String text = intent.getStringExtra("text");
            //int id = intent.getIntExtra("icon",0);

            Context remotePackageContext = null;
            try {
//                remotePackageContext = getApplicationContext().createPackageContext(pack, 0);
//                Drawable icon = remotePackageContext.getResources().getDrawable(id);
//                if(icon !=null) {
//                    ((ImageView) findViewById(R.id.imageView)).setBackground(icon);
//                }
                byte[] byteArray =intent.getByteArrayExtra("icon");
                Bitmap bmp = null;
                if(byteArray !=null) {
                    bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
                Model model = new Model();
                model.setName(title +" " +text);

                if(modelList !=null) {
                }else {
                    modelList = new ArrayList();
                    adapter = new CustomListAdapter(getApplicationContext(), modelList);

            } catch (Exception e) {

3. AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SER                          VICE">
                <action android:name="android.service.notification.NotificationLi                                  stenerService" />
        <receiver android:name="android.notifications.IncomingSms">
               <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        <receiver android:name=".ServiceReceiver" >
                <action android:name="android.intent.action.PHONE_STATE" />

4. Android check Notification Access Setting is enable or not:

//check notification access setting is enabled or not
public static boolean checkNotificationEnabled() {
    return true;
      } else {
         return false;

 }catch(Exception e) {
 return false;

Download Complete Code From Here NotificationListener

Hope, this will helps someone.
Enjoy Coding .... :)

Monday 9 March 2015

Android applying custom fonts

Hello Friends,
      Today, I am sharing my small blog which helps you in applying custom fonts
on android text view from xml or styles file. Its very easy and reduces the number
of java line from your code and also make the performance of your app more better.

1.Placed all your custom fonts file inside assets folder i.e: assets/fonts/digitalism.ttf)
2.Add the path of above custom font file your string.xml file
<string name="FONT_d3_digitalism">fonts/d3-digitalism.ttf</string>
<string name="FONT_digitalism">fonts/digitalism.ttf</string>
<string name="FONT_Mohave_Bold">fonts/Mohave-Bold.ttf</string>
<string name="FONT_Roboto_Black">fonts/Roboto-Black.ttf</string>
<string name="FONT_Roboto_Bold">fonts/Roboto-Bold.ttf</string>
<string name="FONT_Roboto_Medium">fonts/Roboto-Medium.ttf</string>
<string name="FONT_RobotoCondensed_Bold">fonts/RobotoCondensed-Bold.ttf</string>

3. Declartion of style inside values/styles.xml file for eg:
        <style name="CustomDigital">
          <item name="font">@string/FONT_digitalism</item>

4. Inside attrs.xml add this:
<?xml version="1.0" encoding="utf-8"?>
      <declare-styleable name="Fontify">
<attr name="font" format="string" />

   <!-- Allows attribute use in an AppTheme definition -->
   <declare-styleable name="FontifyTheme">
<attr name="fontifyStyle" format="reference"/>
5. finally, In our layout file we have to use this :
         android:text="TextClock" />

For more check below link:

Download Demo Code : CustomTextFont

Hope this will help some one.
Enjoy Coding :)

Thursday 26 February 2015

Google Play Error Retrieving Information RPC:S-2:AEC-2 | How to Fix " Error retrieving information from server RPC:S-2:AEC-2"

Hello Friends ,                                                                              
                Yesterday, I am trying to download my app  
from Google Play Storebut Its give me the error
 "Error retrieving information from server RPC:S-2:AEC-2".
I was worried that may be the signed apk which I uploaded on
"Play store" was Tamper and Corrupted. But its not like
that, its  Google Play Services app  cache issue.

Here are the steps which I follow and then all works fine:

Step 1: Clear all cache and data
Go to  "Settings"  -> "Applications" -> "Manage Applications" -> "Google Play Services
Framework" and select "Clear Data" & "Clear Cache" to remove all the data.

Step 2: Restart your phone and then try to update and download app

Note: After Step 2 if you still facing the same issue then follow below step

Step 3: Remove and Add Your Google Play Store Account.

Go to "Settings" -> "Accounts" -> "Google" -> Select "Your Account" -> "Menu" and Select "Remove Account" and then "Add Your Account".

Now "Restart" your mobile device and try to perform update or download.

Hope this will help Some one....
Enjoy..... :)

Sunday 8 February 2015

Whats New in Android Lollipop | Android lollipop new features

Hello Friends,
       Today, I am sharing about the
  feature added android latest
 version i.e:"Android Lollipop".

1. Material design
A bold, colorful and responsive UI design for consistent, intuitive experiences across all
your devices.

-Android 5.0 brings Material design to Android and gives you an expanded UI toolkit for
 integrating the new design patterns easily in your apps.
-New 3D views let you set a z-level to raise elements off of the view hierarchy and cast 
  real time shadows, even as they move.
- Ripple animations are available for buttons, checkboxes, and other touch controls in 
   your app.
- Animated and non-animated drawables based on XML vector graphics
- A new system-managed processing thread called RenderThread keeps animations 
  smooth even when there are delays in the main UI thread.  
- The RecyclerView widget 
- Drawable animation and styling effects
- Material design animation and activity transition effects

2. Notifications
New ways to control when and how you receive messages – only get interrupted when
you want to be.

- View and respond to messages directly from your
   lock screen. Includes the ability to hide sensitive 
   content for these notifications.
- For fewer disruptions, turn on Priority mode via 
  your device’s volume button so only certain people
  and notifications get through.
- Or schedule recurring downtime, such as from 10.00 p.m. until 
   8.00 a.m., when only  Priority notifications can get through.
- With Lollipop, incoming phone calls won’t interrupt what you’re watching or playing. 
   You can choose to answer the call or just keep doing what you’re doing.
- Control the notifications triggered by your apps; hide sensitive content and priorities or
    turn off the app’s notifications entirely.
- See all your notifications in one place by tapping the top of the screen.

3. Battery
    Power for the long haul

- A battery saver feature that extends device use by up to 90 mins.
- Estimated time left to fully charge is displayed when your device is plugged in.
- Estimated time left on your device before you need to charge again can now be found
   in battery settings.

4. Security
    Keep your stuff safe and sound

- New devices come with encryption automatically turned on to help protect data on lost
  or stolen devices.
- Use Android Smart Lock to secure your phone or tablet by pairing it with a trusted device
  like your wearable or even your car.

5. Device sharing
    More flexible sharing with family and friends

- Multiple users for phones. If you forget your phone, you still can call any of your
   friends (or access any of your messages, photos, etc.)  by simply logging in to 
   another Android phone running Lollipop. Also perfect for families who want to share a
   phone, but not their stuff.
- Guest user for phones and tablets means you can lend your device and not your info
- Screen pinning: pin your screen so that another user can access just that content 
   without messing with your other stuff

6. Accessibility
    Enhanced low-vision and colour-blind capabilities.

- Boost text contrast or invert colours to improve legibility.
- Adjust display to improve colour differentiation.  

7. Media
    Bolder graphics and improved audio, video and camera capabilities.

- Lower latency audio input ensuring that music and communication applications 
   that have strict delay requirements provide an amazing realtime experience.
- Multi-channel audio stream mixing means professional audio applications can now
   mix up to eight channels including 5.1 and 7.1 channels.
- USB Audio support means that you can plug USB microphones, speakers and a
   myriad of other USB audio devices like amplifiers and mixers into your Android device.
- OpenGL ES 3.1 and Android extension pack brings Android to the forefront of
   mobile graphics putting it on par with desktop and console class performance.

8. Runtime and performance
   A faster, smoother and more powerful computing experience.

- ART, an entirely new Android run time, improves application performance and
- Up to 4x performance improvements.
- Smoother UI for complex, visually rich applications.
- Compacting backgrounded apps and services so that you can do more at once.

9. Connectivity
    A better Internet connection everywhere and more powerful Bluetooth low energy capabilities

- Improved network handoffs resulting in limited interruption in connectivity. For 
  example, continue your video chat or VoIP calls without interruption as
  you leave the house and switch from your home Wi-Fi back to mobile.
- Improved network selection logic so that your device connects only if there is a 
   verified internet connection on Wi-Fi.
- Power-efficient scanning for nearby Bluetooth low energy (“BLE”) devices like 
   wearables or beacons.
- New BLE peripheral mode.

10. OK Google
Easy access to information and performing tasks

- Even if your screen is off, you can say "OK Google" on devices with digital signal
   processing support such as Nexus 6 and Nexus 9.
- Talk to Google on the go to get quick answers, send a text, get directions and more.

11. Coming soon: Android TV
            Support for living room devices

- User interface adapted for the living room.
- Less browsing, more watching with personalised recommendations for content like
   films and TV shows.
- Voice search for Google Play, YouTube and supported apps so that you can just 
   see what you want to see.
- Console-style Android gaming on your TV with a gamepad.
- Cast your favourite entertainment apps to your big screen with Google Cast support
   for Android TV devices.

for more check below linkss:

Android calculate the center of Polygon in GoogleMap | Show centroid of polygon on map

Hello Friends,
           Today, I am sharing my code which helps you in calculating Centroid of a polygone
and show it on Google Map.

public static LatLng getCentroid(ArrayList<IGeoPoint> points) {
        double[] centroid = { 0.0, 0.0 };
        for (int i = 0; i < points.size(); i++) {
            centroid[0] += points.get(i).getLatitude();
            centroid[1] += points.get(i).getLongitude();
        int totalPoints = points.size();
        centroid[0] = centroid[0] / totalPoints;
        centroid[1] = centroid[1] / totalPoints;

        return new LatLng(centroid[0], centroid[1]);

Hope, Its helps someone.
Enjoy Coding.... :)

Sunday 1 February 2015

Android Studio Keyboard Short Cut | Android Studio Keyboard Short Cut similar to eclipse

Hello Friends,
               This is my first blog on Android Studio, the official IDE for Android application
development, based on IntelliJ IDEA which offers following features :

- Flexible Gradle-based build system
- Build variants and multiple apk file generation
- Code templates to help you build common app features
- Rich layout editor with support for drag and drop theme editing
- Lint tools to catch performance, usability, version compatibility, and other problems
- ProGuard and app-signing capabilities
- Built-in support for Google Cloud Platform, making it easy to integrate Google Cloud
   Messaging and App Engine
- And much more

Here, I am sharing few things which make the development easy in Android Studio :

1. Setting "Android  Studio" development environment same as Eclipse, we can easily
    use the Eclipse keyboard shortcuts in  "Android Studio". following are the
    steps :
            - Open Android Studio and Click on File
            - Go to Settings (or Ctrl+Alt+S)
            - In Settings select Keymaps from left
            - In Keymaps the setting will be set as  "default" change it to "eclipse"
            - Done, now enjoy all eclipse shortcut in android studio

2.  The default android Studio keyboard short cuts are:
         - Download Android Studio Short Cut  Pdf file : Here

Android Studio Shortcuts You Need the Most
Navigation Shortcuts
Shortcut DescriptionAndroid Studio Shortcut
Go to class Ctrl + N
Go to file Ctrl + Shift + N
Navigate open tabs ALT + Left-Arrow; ALT + Right-Arrow
Lookup recent files CTRL + E
Go to line CTRL + G
Navigate to last edit location CTRL + SHIFT + BACKSPACE
Go to declaration CTRL + B
Go to implementation CTRL + ALT + B
Go to source F4
Go to super Class CTRL + U
Show Call hierarchy Ctrl + Alt + H
Search in path/project CTRL + SHIFT + F
Programming Shortcuts
Shortcut Description Android Studio Shortcut
Reformat code CTRL + ALT + L
Optimize imports CTRL + ALT + O
Code Completion CTRL + SPACE
Issue quick fix ALT + ENTER
Surround code block CTRL + ALT + T
Rename and refactor Shift + F6
Line Comment or Uncomment CTRL + /
Block Comment or Uncomment CTRL + SHIFT + /
Go to previous/next method ALT + UP/DOWN
Show parameters for method CTRL + P
Quick documentation lookup CTRL + Q
General Shortcuts
Shortcut Description Android Studio Shortcut
Delete line CTRL + Y
Safe Delete Alt + DELETE
Close Active Tab CTRL + F4
Build and run SHIFT + F10
Build CTRL + F9
All purpose (Meta)Shortcut CTRL + SHIFT + A

Enjoy Coding......  :)

You can also Check This:
1. How to add support library in Android Studio
2. How to add different .jar file in Android Studio

Monday 19 January 2015

Android Custom Horizontal progress bar | Custom Progress bar

Hello Friends,
                  Today,I am going to share my another blog which helps you in customizing
Horizontal Progress Bar.With the help of this Android tutorial we can also implement
the Android PI Chart view with multiple color.

Actually my need to show some PI Chart like view with multiple different color which fills
dynamically base on the percentage,  without using any 3rd party library. So , I first go
with Horizontal progress bar but in horizontal progress bar only show up-to two level 
progress with different color.

Finally, I have written a custom progress bar code using android seek bar. Using this we
can add "N level" of different color with different percentage.And Its very simple and
easily understandable.

Horizontal Progress bar

Here is my code :

1. MainActivity.java

package com.android.customprogressbar;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;

public class MainActivity extends Activity {

 private CustomProgressBar seekbar;
 private ArrayList progressItemList;
 private ProgressItem mProgressItem;

 protected void onCreate(Bundle savedInstanceState) {
  seekbar = ((CustomProgressBar) findViewById(R.id.seekBar0));

 private void initDataToSeekbar() {
  progressItemList = new ArrayList();
  // red span
  mProgressItem = new ProgressItem();
  mProgressItem.progressItemPercentage = 20;
  Log.i("Mainactivity", mProgressItem.progressItemPercentage + "");
  mProgressItem.color = R.color.red;
  // blue span
  mProgressItem = new ProgressItem();
  mProgressItem.progressItemPercentage = 25;
  mProgressItem.color = R.color.blue;
  // green span
  mProgressItem = new ProgressItem();
  mProgressItem.progressItemPercentage = 35;
  mProgressItem.color = R.color.green;
  //white span
  mProgressItem = new ProgressItem();
  mProgressItem.progressItemPercentage = 20;
  mProgressItem.color =  R.color.white;


 public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.main, menu);
  return true;

2. CustomProgressBar.java

package com.android.customprogressbar;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.SeekBar;

public class CustomProgressBar extends SeekBar {

 private ArrayList mProgressItemsList;

 public CustomProgressBar(Context context) {
  mProgressItemsList = new ArrayList();

 public CustomProgressBar(Context context, AttributeSet attrs) {
  super(context, attrs);

 public CustomProgressBar(Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);

 public void initData(ArrayList progressItemsList) {
  this.mProgressItemsList = progressItemsList;

 protected synchronized void onMeasure(int widthMeasureSpec,
   int heightMeasureSpec) {
  // TODO Auto-generated method stub
  super.onMeasure(widthMeasureSpec, heightMeasureSpec);

 protected void onDraw(Canvas canvas) {
  if (mProgressItemsList.size() > 0) {
   int progressBarWidth = getWidth();
   int progressBarHeight = getHeight();
   int thumboffset = getThumbOffset();
   int lastProgressX = 0;
   int progressItemWidth, progressItemRight;
   for (int i = 0; i < mProgressItemsList.size(); i++) {
    ProgressItem progressItem = mProgressItemsList.get(i);
    Paint progressPaint = new Paint();

    progressItemWidth = (int) (progressItem.progressItemPercentage
      * progressBarWidth / 100);

    progressItemRight = lastProgressX + progressItemWidth;

    // for last item give right to progress item to the width
    if (i == mProgressItemsList.size() - 1
      && progressItemRight != progressBarWidth) {
     progressItemRight = progressBarWidth;
    Rect progressRect = new Rect();
    progressRect.set(lastProgressX, thumboffset / 2,
      progressItemRight, progressBarHeight - thumboffset / 2);
    canvas.drawRect(progressRect, progressPaint);
    lastProgressX = progressItemRight;



2. ProgressItem.java
package com.android.customprogressbar;

public class ProgressItem {
 public int color;
 public float progressItemPercentage;

Download complete Source code : CustomProgress Bar

Hope , this will helps some one .
Enjoy Coding...   :)

Sunday 24 August 2014

Android navigation drawer tutorial | Android navigation drawer with activities | Android Sliding Navigation Drawer – Example

Hello Droid Guys
     Today,  I am going to share the tutorial of  "Android sliding navigation drawer". You also find many tutorial on Google which helps you to show navigation drawer but most of them are using fragment to do that. Here, are the few good tutorial which I follows:
Android Navigation Drawer
Navigation drawer activity

1. https://developer.android.com/design/patterns/navigation-drawer.html
2. http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/

Here, I am going show sliding menu using activity. We can also achieve
the functionality of  Navigation drawer with activities.

This Android tutorial describes How to implement a navigation drawer using  Support Library the DrawerLayout API.

1. Create Drawer Layout :
            To create a navigation drawer, We first declare user interface with a
DrawerLayout as the root view of layout.

Inside the Drawer Layout, add one view that contains the main content for the
screen (your primary layout when the drawer is hidden) and another view that
contains the contents of the navigationdrawer. In this example, I am using a DrawerLayout
with two child. One a Relative layout with webView(the main content), and other
with a ListView for the navigation drawer. The webview is my activity content view.

<?xml version="1.0" encoding="utf-8"?>




    android:layout_height="match_parent" >
          main content




        android:background="#ffffff" >





            android:background="#ffffff" />


        navigation list item



        android:layout_height="match_parent" />








        android:choiceMode="singleChoice" />


2. Initialize the Drawer List :
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);

// set up the drawer's list view with items and click listener
mDrawerList.setAdapter(new MenuDrawerListAdapter(this, menuItemTitles,
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

3. Handle Navigation List click event :

/* The click listener for ListView in the navigation drawer */
public class DrawerItemClickListener implements
	ListView.OnItemClickListener {
	public void onItemClick(AdapterView parent, View view, int position,
		long id) {
		switch (position) {
		case 0: {
		Intent main = new Intent(getApplicationContext(),
		case 1: {
		Intent list = new Intent(getApplicationContext(),

Download Code : Navigation Drawer Demo

Hope this will help someone.
Enjoy Coding...   :)

Sunday 10 August 2014

Android Download Source code | Android Sample Project

Hello Friends,
  This is my small contribution , Now I am sharing the source code of all my android
  post or android tutorial at one place.

Android Tutorial Download Code
Android Custom Calendar Download Code
Android LinkedIn Integration Download Code
Android Crop Image in circular shape like gmail and facebook Download Code
Android facebook like left to right slide navigation Download Code
Android facebook and skype like animated splash screen Download Code
Google map V2 sample with draw polygon or draw geometry and save polygon Download Code
Android video Player Download Code
Android navigation drawer tutorial Download Code
Android Custom Horizontal progress bar |"N" level Horizontl Progress Bar Download Code


Copyright @ 2013 Android Developers Blog.