2013-08-19 66 views
0

我能夠使用輔助功能服務攔截所有通知。此塊是事件發生的地方:如何使用輔助功能API更改Android通知

@Override 
public void onAccessibilityEvent(AccessibilityEvent event) { 
    Log.d(tag, "Inside onAccessibilityEvent"); 
    if (event.getEventType() ==   AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED){ 
     SqlDb db = new SqlDb(this); 
     NotificationObject no = new NotificationObject(); 
     no.setNoficationPackage(String.valueOf(event.getPackageName())); 
     no.setNotificationText(String.valueOf(event.getText().toString())); 
     no.setNotificationDTM(new Date()); 
     db.addNotification(no); 
     Log.d(tag, "Saved event"); 
    } 
} 

我想要做的是更改通知,因此它不被視爲未接電話事件。這是可能在OS 4.0+上做的嗎?

謝謝。

回答

0

另一個應用程序的通知是隻讀的。 因此,像「notification.a = b;」這樣的代碼會導致權限問題。

public void onAccessibilityEvent(AccessibilityEvent event) { 
     // TODO Auto-generated method stub 
     if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) { 
      //Do something, eg getting packagename 
      final String packagename = String.valueOf(event.getPackageName()); 
      final String text = String.valueOf(event.getText()); 

      if(TARGET_PACKAGE.equals(packagename)){ 
       Notification n = (Notification) event.getParcelableData(); 
     } 
}