Android 中的奇怪行为
大家好,我一直在努力寻找这种奇怪行为的原因。我有一项服务将参加来电,其代码如下:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
粘贴评论以删除未答复的问题。请下次回答你自己的问题。
Pasting the comment to remove the question from unanswered. Please answer your own question next time.