Custom Android Auto Application Development

I am an Android developer and I am trying to develop a custom Android Auto application that makes mirroring a simple phone screen. I know that the API is currently only available for music and messaging applications, but I would write a hello world mirroring application. I follow the Google Getting Started tutorial and I use the voice recorder (DHU) provided by Google (at developer.android.com/training/auto/testing/index.html)

but when I click the last button at the bottom of the screen and select “All car apps”, my app does not appear in the list.

All car apps

For example, if an Android device is running on a Samsung tablet (SM-T555), DHU displays this application:

com.google.android.gms, Maps, System UI, Video, SampleAuthenticatorService, SecureSampleAuthService, screen capture, Android Auto, phone, multimedia, return to Google, Samsung Billing, Google application, music on Google Play, music

Available car apps on your Samsung tablet

How to create an application that appears in the list of available applications in Android Auto? Is mirroring possible for a custom application in Android Auto?

+1
source share
3 answers

Create a service like this:

public class HelloWorldService extends CarActivityService { @Override public Class<? extends CarActivity> getCarActivity() { return HelloWorldAutoActivity.class; } } 

Then add the service to your manifest as follows:

  <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> 

Finally, create an xml file called automotive_app_desc under the res folder:

 <automotiveApp> <uses name="service" /> <uses name="projection" /> <uses name="notification" /> </automotiveApp> 

Your HelloWorldAutoActivity.class will work as your main one.

+6
source

That the application was displayed in Auto. You will need to upload it to the playstore on the beta channel.

0
source

Main activity file

The main operation code is the Java MainActivity.java file. This is the actual application file that ultimately converts to the Dalvik executable file and launches your application. The following is the default code generated by the application wizard for Hello World! Appendix -

 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 file

No matter which component you are developing as part of your application, you must declare all its components in the manifest.xml file, which is located in the root of the application project directory. This file works as an interface between the Android OS and your application, so if you do not declare your component in this file, it will not be considered by the OS. For example, the default manifest file would look like this:

 <?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> 

Line file

The strings.xml file is located in the res / values ​​folder and contains all the text that your application uses. For example, the names of buttons, labels, default text, and similar line types are included in this file. This file is responsible for their text content. For example, the default line file would look like this:

 <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> 

Layout file

Activity_main.xml is a layout file available in the res / layout directory that your application refers to when building its interface. You will modify this file very often to change the layout of your application. For your "Hello World!" application, this file will have the following content associated with the default layout -

 <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> 
-3
source

Source: https://habr.com/ru/post/1273181/


All Articles