我是一个Android开发人员,我正在尝试开发一个自定义的Android Auto应用程序,它可以简单地模拟手机屏幕。我知道目前API只适用于音乐和消息应用程序,但我会为镜像一个简单的"hello world“编写一个应用程序。我遵循谷歌入门教程,我正在使用谷歌提供的桌面主机(DHU) (在developer.android.com/training/auto/testing/index.html)
但当我点击显示屏底部的最后一个按钮并选择“所有汽车应用程序”时,我的应用程序不会出现在列表中。
例如,如果Android Auto在三星平板电脑(SM-T555)中启动,则DHU会列出以下应用程序:
com.google.android.gms,地图,系统UI,视频,SampleAuthenticatorService,SecureSampleAuthService,屏幕截图,安卓汽车,手机,媒体,返回谷歌,三星计费,谷歌应用程序,谷歌Play音乐,音乐
Available Car Apps in a Samsung Tablet
如何制作显示在Android Auto的可用应用列表中的应用?是否可以在Android Auto中为自定义应用程序执行镜像?
发布于 2017-03-15 22:56:15
创建如下服务:
public class HelloWorldService extends CarActivityService {
@Override
public Class<? extends CarActivity> getCarActivity() {
return HelloWorldAutoActivity.class;
}
}然后将服务添加到您的清单中,如下所示:
<meta-data
android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc" />
<service
android:name=".HelloWorldService"
android:exported="true"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.google.android.gms.car.category.CATEGORY_PROJECTION" />
<category android:name="com.google.android.gms.car.category.CATEGORY_PROJECTION_OEM" />
</intent-filter>
</service>最后,在res文件夹下创建一个名为automotive_app_desc的xml文件:
<automotiveApp>
<uses name="service" />
<uses name="projection" />
<uses name="notification" />
</automotiveApp>您的HelloWorldAutoActivity.class将作为MainActivity工作。
发布于 2018-02-16 13:12:23
为了让应用程序显示在自动上。你必须把它上传到playstore的beta频道。
发布于 2017-06-27 18:05:21
主活动文件
主要的活动代码是一个Java文件MainActivity.java。这是实际的应用程序文件,最终会转换为Dalvik可执行文件并运行您的应用程序。以下是Hello World的应用程序向导生成的默认代码!应用程序−
package com.example.helloworld;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}清单文件的
作为应用程序的一部分开发的任何组件,都必须在驻留在应用程序项目目录的根目录下的manifest.xml中声明其所有组件。此文件作为Android OS和您的应用程序之间的接口工作,因此如果您不在此文件中声明您的组件,那么OS将不会考虑它。例如,默认清单文件将如下所示:文件−
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tutorialspoint7.myapplication">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>字符串文件
strings.xml文件位于res/values文件夹中,它包含应用程序使用的所有文本。例如,按钮的名称、标签、默认文本和类似类型的字符串都包含在此文件中。这个文件负责它们的文本内容。例如,缺省字符串文件将类似于以下文件−
<resources>
<string name="app_name">HelloWorld</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
</resources>布局文件
activity_main.xml是res/layout目录中的布局文件,您的应用程序在构建其界面时会引用该布局文件。您将非常频繁地修改此文件以更改应用程序的布局。为你的"Hello World!“应用程序中,此文件将包含以下与默认布局−相关的内容
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:text="@string/hello_world"
tools:context=".MainActivity" />
</RelativeLayout>https://stackoverflow.com/questions/42625017
复制相似问题