相关疑难解决方法(0)

在Android上捕获媒体按钮> = 4.0(适用于2.3)

我写了一些服务,使用BroadcastReceiver来捕获媒体按钮之一(来自耳机的"播放按钮"),它在Android 2.3.x(HTC Nexus One或HTC Desire)上运行完美

当我试图在Android 4.0.3(三星Nexus S)上运行它不起作用(我的应用程序没有收到意图"android.intent.action.MEDIA_BUTTON"和"播放"按钮表现如常:停止/启动音乐).

清单内容:

...
<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <receiver android:name=".buttonreceiver.MediaButtonIntentReceiver" >
        <intent-filter android:priority="10000" >
            <action android:name="android.intent.action.MEDIA_BUTTON" />
        </intent-filter>
    </receiver>
...
Run Code Online (Sandbox Code Playgroud)

有没有办法让它在android 4.0.3上运行


编辑:我已尝试提出解决方案,我已添加操作并运行它,但我的接收器仍然没有收到意图.什么更奇怪的代码注册接收器也不起作用:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.about_and_activation_view);

    Log.d("MR", "onCreate - " + getIntent().getAction());

    mReceiver = new MediaButtonIntentReceiver();
    registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_MEDIA_BUTTON));
}
Run Code Online (Sandbox Code Playgroud)

现在我完全糊涂了.

android broadcastreceiver android-manifest android-4.0-ice-cream-sandwich

10
推荐指数
1
解决办法
2万
查看次数