我写了一些服务,使用BroadcastReceiver来捕获媒体按钮之一(来自耳机的"播放按钮"),它在Android 2.3.x(HTC Nexus One或HTC Desire)上运行完美
当我试图在Android 4.0.3(三星Nexus S)上运行它不起作用(我的应用程序没有收到意图"android.intent.action.MEDIA_BUTTON"和"播放"按钮表现如常:停止/启动音乐).
清单内容:
Run Code Online (Sandbox Code Playgroud)... <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> ...
有没有办法让它在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