开发者

Strange behaviour in android

hi guys i have been struggling to find开发者_C百科 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.


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");

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜