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.
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: