Develop an Android Auto custom app

后端 未结 3 1640
情书的邮戳
情书的邮戳 2021-02-03 14:38

I\'m an Android developer and I\'m trying to develop a custom Android Auto app, that does a simple mirroring of the phone screen. I know that currently the API are only availabl

相关标签:
3条回答
  • 2021-02-03 14:56

    In order to have app displayed on the Auto. You will have to upload it to playstore on beta channel.

    0 讨论(0)
  • 2021-02-03 15:01

    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 like this:

        <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 a xml file called automotive_app_desc under your res folder:

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

    Your HelloWorldAutoActivity.class will work as your MainActivity.

    0 讨论(0)
  • 2021-02-03 15:06

    The Main Activity File

    The main activity code is a Java file MainActivity.java. This is the actual application file which ultimately gets converted to a Dalvik executable and runs your application. Following is the default code generated by the application wizard for Hello World! application −

    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);
       }
    }
    

    The Manifest File

    Whatever component you develop as a part of your application, you must declare all its components in a manifest.xml which resides at the root of the application project directory. This file works as an interface between Android OS and your application, so if you do not declare your component in this file, then it will not be considered by the OS. For example, a default manifest file will look like as following file −

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

    The Strings File

    The strings.xml file is located in the res/values folder and it contains all the text that your application uses. For example, the names of buttons, labels, default text, and similar types of strings go into this file. This file is responsible for their textual content. For example, a default strings file will look like as following file −

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

    The Layout File

    The activity_main.xml is a layout file available in res/layout directory, that is referenced by your application when building its interface. You will modify this file very frequently to change the layout of your application. For your "Hello World!" application, this file will have following content related to 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>
    
    0 讨论(0)
提交回复
热议问题