高通Android9 在适配物理按键KeyEvent.KEYCODE_CAMERA没反应,是点击KEYCODE_CAMERA的时候,广播接收不到;
原因是:android8.0及以上系统关于广播的规定:发现果然是对隐式广播做了限定,如果targetSdkVersion >=26,在Manifest里面注册的Receiver可能无法接收到广播消息(我的广播接收者就是像这样静态注册的):
方法:
Y:\project\msm8953_android9\frameworks\base\core\java\com\android\internal\policy\PhoneFallbackEventHandler.java
+++ b/frameworks/base/core/java/com/android/internal/policy/PhoneFallbackEventHandler.java
@@ -33,6 +33,8 @@ import android.view.HapticFeedbackConstants;
import android.view.KeyEvent;
import android.view.View;
import com.android.internal.policy.PhoneWindow;
+import android.provider.MediaStore;
+import android.content.ComponentName;
/**
* @hide
@@ -150,11 +152,21 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler {
mView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
sendCloseSystemWindows();
// Broadcast an intent that the Camera button was longpressed
方法一:更改flag
- Intent intent = new Intent(Intent.ACTION_CAMERA_BUTTON, null);
+ /*Intent intent = new Intent(Intent.ACTION_CAMERA_BUTTON, null);
- intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
+ intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
intent.putExtra(Intent.EXTRA_KEY_EVENT, event);
mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF,
- null, null, null, 0, null, null);
+ null, null, null, 0, null, null);*/
+ 方法二: 使用startActivity打开:
+ //Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
+ Intent intent = new Intent();
+ intent.setComponent(new ComponentName("org.codeaurora.snapcam","com.android.camera.CameraLauncher"));
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ try {
+ mContext.startActivity(intent);
+ } catch (ActivityNotFoundException e) {
+ Log.w(TAG, "cfw-No activity found for INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE.");
+ }
} else {
Log.i(TAG, "Not dispatching CAMERA long press because user "
+ "setup is in progress.");
https://www.jianshu.com/p/9441aa235389
https://blog.csdn.net/fuyinghaha/article/details/78973098
https://blog.csdn.net/csh86277516/article/details/79861583