Android 车载apk 驾驶模式检测 确保行车安全

一 gradle  依赖添加

 最新版本号:

implementation "androidx.car:car:1.0.0-alpha7"

二 在清单文件     所有的activity添加

<meta-data android:name="distractionOptimized" android:value="true" />

 表示这个activity 驾驶模式由我们自己来处理

三 在 需要处理的activity 里添加驾驶模式检测      进而控制遮罩非驾驶安全的功能   比如长文本     视频    二维码

public class SoundActivity extends AppCompatActivity {

    // 驾驶模式检测
    private CarUxRestrictionsHelper carUxRestrictionsHelper;



   @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sound);
        OnUxRestrictionsChangedListener mUxRestrictionsChangedListener = new OnUxRestrictionsChangedListener() {
            @Override
            public void onUxRestrictionsChanged(CarUxRestrictions restrictionInfo) {
                // 对当前驾驶状态有效的Car UX限制的组合。
                int activeRestrictions = restrictionInfo.getActiveRestrictions();
                boolean txtLimit = CarUxRestrictions.UX_RESTRICTIONS_LIMIT_STRING_LENGTH == (activeRestrictions & CarUxRestrictions.UX_RESTRICTIONS_LIMIT_STRING_LENGTH);
                // 控制二维码 或者视频
                boolean videoLimit = CarUxRestrictions.UX_RESTRICTIONS_NO_VIDEO == (activeRestrictions & CarUxRestrictions.UX_RESTRICTIONS_NO_VIDEO);
                if(txtLimit || videoLimit){
                    // 显示遮罩
                    
                }
            }
        };
        carUxRestrictionsHelper = new CarUxRestrictionsHelper(getContext(), mUxRestrictionsChangedListener);
    }


    @Override
    public void onResume() {
        super.onResume();
        //start watching uxRestriction change  开始检测
        carUxRestrictionsHelper.start();
    }

    @Override
    public void onPause() {
        super.onPause();
        //stop watching uxRestriction change  停止检测
        carUxRestrictionsHelper.stop();
    }

}

activeRestrictions: 对当前驾驶状态有效的Car UX限制的组合 不同的flag代表不同的限制类型

 


//No specific restrictions in place, but baseline distraction optimization guidelines need to be adhered to when isDistractionOptimizationRequired() is true.
int	UX_RESTRICTIONS_BASELINE

//All the above restrictions are in effect.
int	UX_RESTRICTIONS_FULLY_RESTRICTED

//Limit the number of items displayed on the screen.
int	UX_RESTRICTIONS_LIMIT_CONTENT

/General purpose strings length cannot exceed the character limit provided by getMaxRestrictedStringLength()
int	UX_RESTRICTIONS_LIMIT_STRING_LENGTH

//No dialpad for the purpose of initiating a phone call.
int	UX_RESTRICTIONS_NO_DIALPAD

//No filtering a list.
int	UX_RESTRICTIONS_NO_FILTERING

//No text entry for the purpose of searching etc.
int	UX_RESTRICTIONS_NO_KEYBOARD

//No setup that requires form entry or interaction with external devices.
int	UX_RESTRICTIONS_NO_SETUP

//No Text Message (SMS, email, conversational, etc.)
int	UX_RESTRICTIONS_NO_TEXT_MESSAGE

//No video - no animated frames > 1fps.
int	UX_RESTRICTIONS_NO_VIDEO

//No text transcription (live or leave behind) of voice can be shown.
int	UX_RESTRICTIONS_NO_VOICE_TRANSCRIPTION

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值