0

I need to get the unread notifications count of any installed app in my device.

For example: get unread notification count of Facebook App, Whats app App, or device Messages, etc., anything present in the notification bar, that hasn't been read yet.

I understand, I would require a content URI of that all those apps. But since I wont be aware of all the URI's how do I go ahead with this. Is there a way to fetch all the notifications from the notification bar?

Mayur More
  • 951
  • 2
  • 15
  • 37

1 Answers1

0
  This is the sample Notification app hope this will help you

package com.example.sampletest;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity {
    ListView l1;
//  public static int [] prgmImages={R.drawable.rlp, R.drawable.skp, R.drawable.ramesan, R.drawable.ramalingam, R.drawable.sweena};

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  l1 = (ListView)findViewById(R.id.list);
  String[] values = new String[] {"ANDROID","Java","NETWORKING","ORACLE","DOTNET","VISUAL BASIC"};

// Define a new Adapter
// First parameter - Context
// Second parameter - Layout for the row
// Third parameter - ID of the TextView to which the data is written
// Forth - the Array of data

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.list_row, R.id.title, values);


// Assign adapter to ListView
l1.setAdapter(adapter); 
 }

 @Override
protected void onStart() {
    // TODO Auto-generated method stub
    super.onStart();
}


@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    Toast.makeText(getApplicationContext(), "Back to foreground",Toast.LENGTH_SHORT).show();
}

@SuppressWarnings("deprecation")
@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
     createNotification();
     /* NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
      Notification notification = new Notification(R.drawable.ic_launcher,
        "New Message", System.currentTimeMillis());

       Intent notificationIntent = new Intent(this, MainActivity.class);
      PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
        notificationIntent, 0);

       notification.setLatestEventInfo(MainActivity.this,"Message",
        "RUNNING IN BACKGROUND", pendingIntent);
      notificationManager.notify(9999, notification);*/

}

@Override
protected void onStop() {
    // TODO Auto-generated method stub
    super.onStop();
}

@Override
protected void onDestroy() {
    // TODO Auto-generated method stub
    super.onDestroy();
}

@SuppressWarnings("deprecation")
private void createNotification() {

    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    int unique_id = 145558;
    Intent nintent = new Intent();
    nintent.setClass(this, MainActivity.class);

    PendingIntent pin = PendingIntent.getActivity(getApplicationContext(),
            0, nintent, 0);
    String title = "Notification";
    String body = "RUNNING IN BACKGROUND";
    Notification n = new Notification(R.drawable.ic_launcher, body,
            System.currentTimeMillis());
    n.contentIntent = pin;
    n.setLatestEventInfo(getApplicationContext(), title, body, pin);
    n.flags |= Notification.FLAG_AUTO_CANCEL;
    n.defaults = Notification.DEFAULT_ALL;
    nm.notify(unique_id, n);

}

}
Vivek Elangovan
  • 238
  • 2
  • 16
  • 1
    Vivek, I do not want to create notifications. I need to fetch notifications already present in notification bar. Example fetch notification from gmail app, facebook app, whats app, app, etc. – Mayur More May 09 '14 at 11:36