繁体   English   中英

Android Automotive:无法识别启动活动:未找到默认活动

[英]Android Automotive: Could not identify launch activity: Default Activity not found

我刚刚创建了我的第一个 Android Automotive 项目:

图片

当我运行AndroidAutoDemo.mobile模块时,它工作正常:

在职的

不幸的是,当我切换到AndroidAutoDemo.automotive模块时,我得到:

无法识别启动活动:未找到默认活动启动活动时出错无法在所有设备上启动应用程序

这是AndroidAutoDemo.automotive模块中的 Android Manifest 文件(默认保留):

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

    <uses-feature
        android:name="android.hardware.type.automotive"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:appCategory="audio"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AndroidAutoDemo" />

</manifest>

这是我的移动模拟器:

模拟器

  • 我该如何解决?

每个清单文件应包含有关可用活动和启动器活动的信息。 启动器活动需要使用一些额外的 Intent 过滤器来定义,例如:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.car">

<uses-permission android:name="android.car.permission.CAR_POWERTRAIN" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.DeviceDefault.NoActionBar">
    <activity android:name="com.example.car.MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

要运行汽车应用程序,您需要汽车模拟器和带有 Manifest 的汽车风格,如下所示。 谷歌还没有提供汽车模拟器,但您可以从 Polestar https://developer.polestar.com/sdk/polestar2-sys-img.xml和沃尔沃https://developer.volvocars 等获得其他开源模拟器。 com/sdk/volvo-sys-img.xml您不必添加新活动

如果想了解您可以通过示例源代码https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:car/app/app-samples/helloworld/

`

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="androidx.car.app.sample.helloworld"
    android:versionCode="1"
    android:versionName="1.0">

    <!-- Various required feature settings for an automotive app. -->
    <uses-feature
        android:name="android.hardware.type.automotive"
        android:required="true" />
    <uses-feature
        android:name="android.software.car.templates_host"
        android:required="true" />
    <uses-feature
        android:name="android.hardware.wifi"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.screen.portrait"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.screen.landscape"
        android:required="false" />

    <application
      android:label="@string/app_name"
      android:icon="@drawable/ic_launcher"
      android:extractNativeLibs="false">

        <meta-data
            android:name="com.android.automotive"
            android:resource="@xml/automotive_app_desc"
            tools:ignore="MetadataTagInsideApplicationTag" />

        <meta-data android:name="androidx.car.app.minCarApiLevel"
            android:value="1"
            tools:ignore="MetadataTagInsideApplicationTag" />

        <service
            android:name="androidx.car.app.sample.helloworld.common.HelloWorldService"
            android:exported="true">
          <intent-filter>
            <action android:name="androidx.car.app.CarAppService" />
          </intent-filter>
        </service>

        <activity
            android:name="androidx.car.app.activity.CarAppActivity"
            android:theme="@android:style/Theme.DeviceDefault.NoActionBar"
            android:exported="true"
            android:launchMode="singleTask"
            android:label="@string/app_name">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <meta-data android:name="distractionOptimized" android:value="true"/>
        </activity>
    </application>
</manifest>

`

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM