Skip to content

Instantly share code, notes, and snippets.

@fjallstrom
Created February 28, 2014 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fjallstrom/9270491 to your computer and use it in GitHub Desktop.
Save fjallstrom/9270491 to your computer and use it in GitHub Desktop.
@Override
public void onNotificationPosted(StatusBarNotification statusBarNotif) {
Notification notif = statusBarNotif.getNotification();
if (notif != null){
Bundle extras = notif.extras;
Intent intent = new Intent(MainActivity.INTENT_NOTIFICATION);
intent.putExtras(notif.extras);
sendBroadcast(intent);
Bundle intentExtras = intent.getExtras();
String notifTitle = intentExtras.getString(Notification.EXTRA_TITLE);
CharSequence notifText = intentExtras.getCharSequence(Notification.EXTRA_TEXT);
int notificationId = statusBarNotif.getId();
//Check if the notification is from snapchat, and the id matches the printscreen id from notification.
if(statusBarNotif.getPackageName().equals(snapchatPackageName)){
if(notificationId == printScreenId){
//Split the String to get the username.
String arr[] = notifText.toString().split(" ", 2);
String userName = arr[0];
//Send to api.
runHttpPost(userName);
//Cancel all notifications.
NLService.this.cancelAllNotifications();
}
}
else{
Log.i("Other", "Another type of notification.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment