java - 清除来电接收器上的来电通知

标签 java android

我有来电接收器,我想在收到广播时清除来电通知,我该怎么办?

public class IncommingCallReceiver extends BroadcastReceiver
{
    public void onReceive(final Context context, final Intent intent) 
    {
        //some method
    }
}

最佳答案

使用 ID 取消通知

NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); 
notificationManager.cancel(id);

创建通知时创建一个 ID

  // Sets an ID for the notification
    int mNotificationId = 001;
    // Gets an instance of the NotificationManager service
    NotificationManager mNotifyMgr = 
            (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // Builds the notification and issues it.
    mNotifyMgr.notify(mNotificationId, mBuilder.build());

引用here

关于java - 清除来电接收器上的来电通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27706642/

相关文章:

java - 用于与常量进行比较的 PMD 规则

Java WebSocket HandshakeRequest getParameterMap 方法

android.support.design.widget.TabLayout 无法与 ViewPager 一起正常工作

java - 如何从 context.xml 资源获取 URL

java - 使用 JPA 从现有数据库检索信息

java - 从 HashMap<Integer, List<Integer>> 获取每个数字的最大出现次数

android - FragmentPagerAdapter 中的 fragment 选项菜单

android - DialogFragment 相对于 AlertDialog 的优势

android - 将 admob 与静态横幅一起使用

android - 在 ANDROID 中使用 json 解析大小约为 3MB 的数据?