广播接收器没有收到相机上的按钮键preSS [英] BroadcastReceiver don't receive keypress on Camera button

查看:192
本文介绍了广播接收器没有收到相机上的按钮键preSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,当我的应用程序在后台和I $页上$ PSS玩一些音 相机该按钮我做这个简单的步骤。

I am trying to play some tone when my application is in background and I press on "Camera" button for that I am doing this simple steps.


  1. 创建广播接收器

public class CameraButtonListener extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        ToneGenerator tone = new ToneGenerator(AudioManager.STREAM_DTMF, 100);
        tone.startTone(0,2000);
        abortBroadcast();
    }
}


  • 注册 BrodcastReceiver 的onCreate 梅索德。

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        MediaButtonBrodcastReceiver receiver = new MediaButtonBrodcastReceiver();        
        IntentFilter filter = new IntentFilter(Intent.ACTION_CAMERA_BUTTON);
        filter.setPriority(25645895);
        registerReceiver(receiver,filter);      
    }
    


  • 添加brodcast接收器Android清单。

  • Adding brodcast receiver to android manifest.

    <receiver android:enabled="true" android:exported="true" android:name=".CameraButtonListener">
    <intent-filter android:priority="25645895">
        <action android:name="android.intent.action.CAMERA_BUTTON" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
    

    我启动我的应用程序后,再preSS菜单键,应用程序转到后台,我以后美元,拍照键并没有什么heppens p $ PSS,只有摄像头应用程序中打开。也许我做错了什么,或我错过了什么?

    After I launch my application, then press menu button and application goes to the background, after I press on Camera Button and nothing heppens, only camera application is opened. Maybe I am doing something wrong or I have missed something ?

    我用索尼爱立信Xperia Arc手机采用Android 2.3.4操作系统版本。

    I use Sony Ericsson XPeria Arc phone with Android 2.3.4 OS version.

    推荐答案

    摆脱&LT;类别&GT; &LT元素;接收器GT ; 元素,如果你使用的是第三步。这广播可能没有一个类别 - 你通常只看到类用于意图对象startActivity()

    Get rid of the <category> element in your <receiver> element, if you are using step #3. That broadcast probably does not have a category -- you usually only see categories on Intent objects used for startActivity().

    请注意,您的第2步中没有指定一个类的的IntentFilter ,这是很好的。

    Note that your step #2 does not specify a category with its IntentFilter, which is fine.

    这篇关于广播接收器没有收到相机上的按钮键preSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆