Can we clear the missed call notification? cancelMissedCallsNotification()

bsnqt

Active Member
Licensed User
Longtime User
I tried to make a small library using Eclipse to clear the missed call notification. My library has successfully been created, it does not give any error when I run demo but does not work at all (cannot clear the missed call notification).

Any enlightening or advice will be greatly appreciated. Thank you so much.

B4X:
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
 
import android.database.Cursor;
import android.provider.CallLog;
import android.util.Log;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

B4X:
@Permissions(values = {"android.permission.MODIFY_PHONE_STATE"})

B4X:
@SuppressWarnings({ "unchecked", "rawtypes" })
        public void cancelMissedCallsNotification() {
 
    try {
        Class serviceManagerClass = Class.forName("android.os.ServiceManager");
        Method getServiceMethod = serviceManagerClass.getMethod("getService", String.class);
        Object phoneService = getServiceMethod.invoke(null, "phone");
        Class ITelephonyClass = Class.forName("com.android.internal.telephony.ITelephony");
        Class ITelephonyStubClass = null;
        for (Class clazz : ITelephonyClass.getDeclaredClasses()) {
            if (clazz.getSimpleName().equals("Stub")) {
                ITelephonyStubClass = clazz;
                break;
                }
                      }
          if (ITelephonyStubClass != null) {
          Class IBinderClass = Class.forName("android.os.IBinder");
          Method asInterfaceMethod = ITelephonyStubClass.getDeclaredMethod("asInterface", IBinderClass);
          Object iTelephony = asInterfaceMethod.invoke(null, phoneService);
          if (iTelephony != null) {
                  Method cancelMissedCallsNotificationMethod = iTelephony.getClass().getMethod("cancelMissedCallsNotification");
                  cancelMissedCallsNotificationMethod.invoke(iTelephony);
                  } else {
          Log.w("TTT", "Telephony service is null, can't call cancelMissedCallsNotification");
                  }
                  } else {
                      Log.d("TTT", "Unable to locate ITelephony.Stub class!");
                  }
              } catch (ClassNotFoundException ex) {
          Log.e("TTT", "Failed to clear missed calls notification due to ClassNotFoundException!", ex);
              } catch (InvocationTargetException ex) {
          Log.e("TTT", "Failed to clear missed calls notification due to InvocationTargetException!", ex);
          } catch (NoSuchMethodException ex) {
          Log.e("TTT", "Failed to clear missed calls notification due to NoSuchMethodException!", ex);
          } catch (Throwable ex) {
          Log.e("TTT", "Failed to clear missed calls notification due to Throwable!", ex);
          }
    }
 
Last edited:

bsnqt

Active Member
Licensed User
Longtime User
I posted the question, but found the answer... though it is not a good news.

Since Android 2.3, Google prohibited third party application (i.e. non-system app) to make use of MODIFY_PHONE_STATE permission. One of the consequences is that all 3rd party phone dialer application can no longer clear missed call icon at notification bar. (Even at Android 2.2 or older, we need undocumented API to do so)
With original Android phone dialer, the missed call indicator disappeared when call log page is shown. Third part applications on Android 2.3 cannot do so. It would be annoying that the missed call indicator keep showing. We may tap the "clear" button to clear all icons on notification bar. However, the missed call count remain. When the missed call indication appear again for one more missed call, the missed call count accumulate.

To achieve my goal I still need a workaround. What I plan to do is to call the phonepad dialer (it will clear the missed call notification), and right after I will hide it again. That can help me out in this situation temporarily, but there are many "adverse events"... For example, doing this will bring the dialer to the front, if the user is running another program, it will not be an comfortable experience...

Do you have any better idea or better way to achieve the same goal, please advise? Thank you so much.

To call the dialer (code from this Forum):

B4X:
Dim intClear As Intent
intClear.Initialize(intClear.ACTION_VIEW, "tel:" & "")
StartActivity(intClear)

And finally to hide it back:

B4X:
intClear.Initialize(intClear.ACTION_MAIN, "")
intClear.AddCategory("android.intent.category.HOME")
intClear.Flags = 268435456
StartActivity(intClear)
 
Last edited:
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
bsnqt .. I certainly can't help you but many thanks for the above. I have written a small phone blocker app for personal use that targets tele marketing calls that refuse to leave me alone. They are all different numbers but all start with the same three digits. It works well, but one hitch was not being able to clear the missed call notification . I will certainly try out your code

Cheers mj
 
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
@mangojack: glad to hear my workaround can help you :) we are hear to share and to learn... though I think my workaround is still troublesome... If you still cannot clear the notifications, you may need to give a short pause between the two "calling" the phone interface and "hiding" it.
Still waiting for others to help us...
 
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
@mangojack: My workaround does NOT work on some devices, for example Galaxy Note 2, the reason is when you call the phone app, it will not clear the missed call notification, as in Galaxy Note the log is not located in the same Tab with phone dialpad (main interface). So when you call the phone app using "ACTION_VIEW" only the dialpad brings to front (the call log still stays in its own tab, so it will not clear the notification) :(
 
Upvote 0
Top