A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© shihao 中级黑马   /  2016-1-25 17:31  /  2349 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

try {
Intent intent = new Intent("android.intent.action.MEDIA_BUTTON");
            KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK);
            intent.putExtra("android.intent.extra.KEY_EVENT",keyEvent);
            localContext.sendOrderedBroadcast(intent,"android.permission.CALL_PRIVILEGED");
            intent = new Intent("android.intent.action.MEDIA_BUTTON");
            keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK);
            intent.putExtra("android.intent.extra.KEY_EVENT",keyEvent);
            localContext.sendOrderedBroadcast(intent,"android.permission.CALL_PRIVILEGED");
            Intent localIntent1 = new Intent(Intent.ACTION_HEADSET_PLUG);
            localIntent1.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            localIntent1.putExtra("state", 1);
            localIntent1.putExtra("microphone", 1);
            localIntent1.putExtra("name", "Headset");
            localContext.sendOrderedBroadcast(localIntent1,
            "android.permission.CALL_PRIVILEGED");
            Intent localIntent2 = new Intent(Intent.ACTION_MEDIA_BUTTON);
            KeyEvent localKeyEvent1 = new KeyEvent(KeyEvent.ACTION_DOWN,
            KeyEvent.KEYCODE_HEADSETHOOK);
            localIntent2.putExtra("android.intent.extra.KEY_EVENT",
            localKeyEvent1);
            localContext.sendOrderedBroadcast(localIntent2,
            "android.permission.CALL_PRIVILEGED");
            Intent localIntent3 = new Intent(Intent.ACTION_MEDIA_BUTTON);
            KeyEvent localKeyEvent2 = new KeyEvent(KeyEvent.ACTION_UP,
            KeyEvent.KEYCODE_HEADSETHOOK);
            localIntent3.putExtra("android.intent.extra.KEY_EVENT",
            localKeyEvent2);
            localContext.sendOrderedBroadcast(localIntent3,
            "android.permission.CALL_PRIVILEGED");
            Intent localIntent4 = new Intent(Intent.ACTION_HEADSET_PLUG);
            localIntent4.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            localIntent4.putExtra("state", 0);
            localIntent4.putExtra("microphone", 1);
            localIntent4.putExtra("name", "Headset");
            localContext.sendOrderedBroadcast(localIntent4,
            "android.permission.CALL_PRIVILEGED");
            } catch (Exception e2) {
            e2.printStackTrace();
            Intent meidaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);  
                       KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK);  
                       meidaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT,keyEvent);  
                       localContext.sendOrderedBroadcast(meidaButtonIntent, null);
            }


低版本可以 高版本实现不了

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马