Android 中的奇怪行为

发布于 2024-11-03 08:40:26 字数 1070 浏览 1 评论 0原文

大家好,我一直在努力寻找这种奇怪行为的原因。我有一项服务将参加来电,其代码如下:

Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON);
    KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN,
            KeyEvent.KEYCODE_HEADSETHOOK);
    i.putExtra(Intent.EXTRA_KEY_EVENT, event);

    ctx.sendOrderedBroadcast(i, null);

    Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
    buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(
            KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
    ctx.sendOrderedBroadcast(buttonUp,
                    "android.permission.CALL_PRIVILEGED");

上面的代码工作很酷。我有一个活动,可以播放存储在 SD 卡中的一些简单的音频文件。其代码如下:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW);         
        Uri data = Uri.parse("file://"+Environment.getExternalStorageDirectory()
                .getAbsolutePath()+"/" + fileName);
        String type = "audio/mp3";
        intent.setDataAndType(data, type);
        startActivity(intent);

这也工作得很好。但问题是,一旦要播放的第二个活动开始并完成,参加通话的第一部分就会停止工作。我不知道为什么会这样。有谁能说出其中的原因吗?

hi guys i have been struggling to find the reason for this strange behaviour. I have a service which will attend the incomming call and that code as follows:

Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON);
    KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN,
            KeyEvent.KEYCODE_HEADSETHOOK);
    i.putExtra(Intent.EXTRA_KEY_EVENT, event);

    ctx.sendOrderedBroadcast(i, null);

    Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
    buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(
            KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
    ctx.sendOrderedBroadcast(buttonUp,
                    "android.permission.CALL_PRIVILEGED");

And the above code works cool. And i have a activity from where i can play some simple audio file stored in the sdcard. And the code for that follows:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW);         
        Uri data = Uri.parse("file://"+Environment.getExternalStorageDirectory()
                .getAbsolutePath()+"/" + fileName);
        String type = "audio/mp3";
        intent.setDataAndType(data, type);
        startActivity(intent);

and this too works fine. but the problem is that once the second activity thats to play is started and finished the first part to attend the call stops working. i dont know why it is happening like this. Can anybody tel the reason for that.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事和酒 2024-11-10 08:40:26

粘贴评论以删除未答复的问题。请下次回答你自己的问题。

大家好,经过一天的努力找到了解决方案。我所做的只是
而不是发送orderedBroadcast,只需发送广播即可
现在工作正常...... ctx.sendBroadcast(i);而不是
ctx.sendOrderedBroadcast(i,"android.permission.CALL_PRIVILEGED");

Pasting the comment to remove the question from unanswered. Please answer your own question next time.

Hi Guys after a day of struggling found a solution. All that i did is
instead of sending orderedBroadcast simply send the broadcast and it
works fine now.... ctx.sendBroadcast(i); instead of
ctx.sendOrderedBroadcast(i,"android.permission.CALL_PRIVILEGED");

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文