开发者

Update missed calls notification on android

I need to cancel the m开发者_StackOverflow社区issed calls notification for a certain number. I've seen the NotificationMgr class on com.android.phone but i'm unable to call it trough reflection. Is there any other way?


The code below will cancel the missed call notification.

To get the method work correctly, you must gain MODIFY_PHONE_STATE permission in AndroidManifest.xml like

    <uses-permission android:name="android.permission.MODIFY_PHONE_STATE"></uses-permission>

in your AndroidManifest.xml

String Log_Tag = "log";
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(LOG_TAG, "Telephony service is null, can't call "
                        + "cancelMissedCallsNotification");
            }
        }
        else
        {
            Log.d(LOG_TAG, "Unable to locate ITelephony.Stub class!");
        }
    } catch (ClassNotFoundException ex)
    {
        Log.e(LOG_TAG,
                "Failed to clear missed calls notification due to ClassNotFoundException!", ex);
    } catch (InvocationTargetException ex)
    {
        Log.e(LOG_TAG,
                "Failed to clear missed calls notification due to InvocationTargetException!",
                ex);
    } catch (NoSuchMethodException ex)
    {
        Log.e(LOG_TAG,
                "Failed to clear missed calls notification due to NoSuchMethodException!", ex);
    } catch (Throwable ex)
    {
        Log.e(LOG_TAG, "Failed to clear missed calls notification due to Throwable!", ex);
    }

The original link is http://sites.google.com/site/t2k269group/development-diary/reset-missed-calls-notification

If some know how to use the reflection to access class in com.android.phone, please tell me.


You cannot affect anyone other application's Notifications, let alone one for missed calls.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜