0

我需要在我的設備中獲取已安裝的應用的未讀通知數從通知欄獲取通知

例如:獲取Facebook應用程序,Whats應用程序應用程序或設備消息等的未讀通知計數,通知欄中存在的尚未讀取的任何內容。

據我所知,我會要求所有這些應用程序的內容URI。但是由於我不知道所有的URI,我該如何繼續這個。有沒有辦法通過從通知欄獲取所有通知?

回答

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); 

} 

} 
+1

Vivek,我不想創建通知。我需要獲取通知欄中已經存在的通知。從Gmail應用,Facebook應用,whats應用,應用等獲取通知示例 –