zoukankan      html  css  js  c++  java
  • [Android]Android5.0实现静默接听电话功能

    原因:

    android曾经能够通过AIDL进行静默接听。可是5.0以后就被谷歌给屏蔽了。这时候我们仅仅能通过其它方式实现了。

    解决方式:

    try {
                Runtime.getRuntime().exec("input keyevent " +
                        Integer.toString(KeyEvent.KEYCODE_HEADSETHOOK));
            } catch (IOException e) {
                // Runtime.exec(String) had an I/O problem, try to fall back
                String enforcedPerm = "android.permission.CALL_PRIVILEGED";
                Intent btnDown = new Intent(Intent.ACTION_MEDIA_BUTTON).putExtra(
                        Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN,
                                KeyEvent.KEYCODE_HEADSETHOOK));
                Intent btnUp = new Intent(Intent.ACTION_MEDIA_BUTTON).putExtra(
                        Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP,
                                KeyEvent.KEYCODE_HEADSETHOOK));
    
                mContext.sendOrderedBroadcast(btnDown, enforcedPerm);
                mContext.sendOrderedBroadcast(btnUp, enforcedPerm);
            }
    

    简单说就是发送一个耳机按下接听的事件。欺骗系统。

  • 相关阅读:
    linux screen工具
    nginx 启动重启脚本
    Docker入门
    时间管理定律
    贪婪算法
    指针与指针的地址
    双向链表(前插操作,删除操作)
    Trie树检索字符串
    函数调用
    字符串匹配算法
  • 原文地址:https://www.cnblogs.com/tlnshuju/p/6947087.html
Copyright © 2011-2022 走看看