android / car-samples

Multiple samples showing best practices for car app development on both Android Auto and Android Automotive OS.
Apache License 2.0
355 stars 165 forks source link

Unavailable, for your safety. This activity is not available while driving. #6

Open asimwaleed opened 3 years ago

asimwaleed commented 3 years ago

I just create sample project for android automotive OS in which i just display "Hello World" text, but the issue is when i install my apk on emulator (Polestar 2) and increase the speed (from 0 to 3, 4 any number) it shows me this text, "Unavailable, for your safety. This activity is not available while driving." I also create config.xml file in which i make my activity white listed also add meta-data tag in manifest but still got this message. Below is my config.xml and manifest.

<?xml version="1.0" encoding="utf-8"?>

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <!--  Comma separated list of activities that need to be exempted from getting
          blocked in a UX restricted state.
          Format of each entry is either to specify package name to allowlist the whole package or
          use format of "packagename/activity_classname" for tagging each activities.
          For general guidelines to design distraction optimized apps, please refer
          to Android Auto Driver Distraction Guidelines. -->
    <string name="activityWhitelist" translatable="false">mypackage/mypackage.myapplication.TestActivity</string>

</resources>

--Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="mypackage.myapplication">

    <uses-feature
        android:name="android.hardware.type.automotive"
        android:required="true" />
    <uses-permission android:name="android.car.permission.CAR_POWERTRAIN" />
    <uses-permission android:name="android.car.permission.CAR_SPEED" />
    <uses-permission android:name="android.car.permission.CAR_ENERGY" />
    <uses-permission android:name="android.car.permission.CAR_UX_RESTRICTIONS_CONFIGURATION" />
    <uses-permission android:name="android.car.permission.CAR_DRIVING_STATE"/>
    <uses-permission android:name="androidx.car.app.NAVIGATION_TEMPLATES"/>
    <uses-permission android:name="androidx.car.app.ACCESS_SURFACE"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@android:style/Theme.DeviceDefault.NoActionBar">
        <activity android:name=".TestActivity"
            android:exported="true"
            android:label="e">
            <meta-data android:name="distractionOptimized" android:value="true"/>
            <intent-filter>
                <action android:name="android.intent.action.APPLICATION_PREFERENCES"/>
            </intent-filter>
        </activity>
    </application>

</manifest>

I also tried your sample application, but the behaviour is same.

Morteza-Rastgoo commented 2 years ago

No updates on this?

asimwaleed commented 2 years ago

No updates on this?

No update from google

AlirezaGhadimi commented 2 years ago

Hi; There is no update on this issue? How to tell android automotive that the app is safe to be used when driving? I have tried adding the following line to the manifest file, but it does not have any effect.

<meta-data android:name="distractionOptimized" android:value="true" />
ocihangir commented 1 year ago

It looks like you need to set distractionOptimized in the manifest file and your app must be from a trusted source such as Play Store. See the SO answer : https://stackoverflow.com/questions/65668981/how-to-get-permission-for-driver-distraction-optimized

I believe the Android emulator should have a setting to allow the application based on the manifest file only.