0

Based on the notification title which says "you have been logged out", I want to trigger clear app data event in android. I browsed a lot. didn't get what I needed. can someone help?

Abdul Waheed
  • 4,540
  • 6
  • 35
  • 58

1 Answers1

-1

The Simplest way to do this is

private void deleteAppData() {
 try {
// clearing app data
String packageName = getApplicationContext().getPackageName();
Runtime runtime = Runtime.getRuntime();
runtime.exec("pm clear "+packageName);

  } catch (Exception e) {
  e.printStackTrace();
 } }

This will clear the data and remove your app from memory. It is equivalent to clear data option under Settings --> Application Manager --> Your App --> Clear data

As an alternate I have one more option i.e. ((ActivityManager)context.getSystemService(ACTIVITY_SERVICE)‌​) .clearApplicationUserData();

But it has a limitation that it only work API level >=19

Abdul Waheed
  • 4,540
  • 6
  • 35
  • 58
  • Thank you. but first, I need to check for notification title. and if it matches the string log out, only then I need to fire this event. I tried what you have written above, but it doesn't work. Any Idea how do I check notification content first and then trigger the event? – Hafsa Mushtaq Oct 29 '17 at 13:04
  • you need to add notification data. What are you getting in notification data post it here – Abdul Waheed Oct 29 '17 at 13:18
  • 1
    Hahaha you literally copy/pasted this other [answer](https://stackoverflow.com/a/42228794/1797127) without even referencing it... – Hugo Allexis Cardona Apr 21 '18 at 05:30