Android Auto

Dans Studio, Tools/Android/Sdk Manager sélectionnez les cases Android Auto dans l’onglet SDK Tools

Créez un projet avec comme version Android 5.0 (API level 21)  minimum et sélectionnez le type d’application « Android Auto »

Vous avez le choix entre deux types d’application :

MEDIA ou MESSAGES

A) Debug :

Référencehttps://developer.android.com/training/auto/testing/index.html

et https://developer.android.com/training/cars/testing#test-auto

Sur l’application « Android auto » de votre SmartPhone passez en mode développeur en allant dans le menu A propos puis tapez 10 fois sur le texte A propos d’Android Auto pour passer en mode développeur.

Sélectionnez « démarrer le serveur unité principale » dans le menu (…)

Lancez l’émulation de l’écran Android Auto sur le pc :

Sous Ubuntu :

cd ./Android/Sdk/extras/google/auto

chmod +x ./desktop-head-unit

Sous Windows :

a) ouvrez une fenêtre de ligne de commande, sous windows : cmd

b) Redirigez le port 5277 : adb forward tcp:5277 tcp:5277

c) allez dans le répertoire auto : cd \Profile\<…>\AppData\Local\Android\Sdk\extras\google\auto

d) lancez l’émulateur : .\desktop-head-unit

Le terminal affiche : Connecting over ADB to localhost:5277…connected.

et une fenêtre d’émulation s’ouvre….

Ces commandes peuvent être rassemblées dans un fichier .bat :

 @echo off  
 echo Connectez votre smartphone puis   
 pause  
 adb forward tcp:5277 tcp:5277  
 d:  
 cd \extras\google\auto  
 .\desktop-head-unit  

b) Ajout des fonctionnalités de messages dans une application existante :

https://developer.android.com/training/auto/messaging/index.html

  1. S’assurer que la version de sdk est > à 21
  2. Créez un répertoire « xml » dans le répertoire « res » et ajouter le code :

<?xml version= »1.0″ encoding= »utf-8″?>

<automotiveApp>

<uses name= »notification »/>

</automotiveApp>

Add a manifest entry

In your app’s manifest (AndroidManifest.xml), provide a reference to the Auto XML configuration file you created in the previous section. Add a"com.google.android.gms.car.application" metadata entry under the <application> element that references your Auto XML configuration file. Omit the .xml file extension when specifying the configuration filename.

The following code snippet shows how to include this reference in your manifest.

<application>

    ...
    <meta-data android:name="com.google.android.gms.car.application"
     android:resource="@xml/automotive_app_desc"/>

</application>

A

3. Création du BroadCast Receiver pour recevoir l’information de lecture de l’utilisateur :

File->New->Other->BroadCast Receiver et nommer (MyMessageHeard)

et ajouter dans le paragraphe « receiver »  créé dans le manifest les lignes :

<intent-filter>
<action android:name= »com.androstock.currentlocation.MY_ACTION_MESSAGE_HEARD » />
</intent-filter>

4. Creation d’un intent pour agir une fois la notification lue

File->New->Other->BroadCast Receiver et nommer (MyMessageReply)

et ajouter dans le paragraphe « receiver »  créé dans le manifest les lignes :

<intent-filter>
<action android:name= »com.androstock.currentlocation.MY_ACTION_MESSAGE_REPLY » />
</intent-filter>

5. Dans le fichier « build.gradle module app », dans le paragraphe « dépendencies » ajoutez la ligne suivante (22.11.1 se rapporte à la version de sdk utilisée. Si vous utilisez la 25 alors  écrivez 25.3.1)…

compile "com.android.support:support-v4:22.1.1"

5. Résumé :

Exemple d’application envoyant soit une notification simple, soit une notification à Android AUTO à télécharger ici

Exemple de notification simple affichée sur l’écran du smartphone  :

 public void sendNotification() {  
     /** Create an intent that will be fired when the user clicks the notification.  
      */  
     Intent intent = new Intent(Intent.ACTION_VIEW,  
         Uri.parse("http://developer.android.com/reference/android/app/Notification.html"));  
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);  
     /**  
      * Use NotificationCompat.Builder to set up our notification.  
      */  
     NotificationCompat.Builder builder = new NotificationCompat.Builder(this);  
     /** Set the icon that will appear in the notification bar. T  
      */  
     builder.setSmallIcon(R.drawable.ic_stat_notification);  
     // Set the intent that will fire when the user taps the notification.  
     builder.setContentIntent(pendingIntent);  
     // Set the notification to auto-cancel.   
     builder.setAutoCancel(true);  
     /**  
      *Build the notification's appearance.  
      */  
     builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));  
     /**  
      * Set the text of the notification.   
      * 1. The content title, which appears in large type at the top of the notification  
      * 2. The content text, which appears in smaller text below the title  
      * 3. The subtext, which appears under the text on newer devices (>4.2)  
      */  
     builder.setContentTitle("BasicNotifications Sample");  
     builder.setContentText("Time to learn about notifications!");  
     builder.setSubText("Tap to view documentation about notifications.");)  
     /**  
      * Send the notification.   
      */  
     NotificationManager notificationManager = (NotificationManager) getSystemService(  
         NOTIFICATION_SERVICE);  
     notificationManager.notify(NOTIFICATION_ID, builder.build());  
   }  

Références :

https://developer.android.com/training/auto/start/index.html

http://mobilesiri.com/develop-app-for-android-auto/

https://codelabs.developers.google.com/codelabs/androidauto-messaging/index.html?index=..%2F..%2Findex#0

https://github.com/googlesamples/android-UniversalMusicPlayer

https://developer.android.com/training/auto/messaging/index.html#messaging

Articles récents
Commentaires récents
fatima dans Bienvenue !
AdminDroid dans Bienvenue !
fatima dans Bienvenue !
Archives
Catégories
%d blogueurs aiment cette page :