2016-04-06 1 views
3

Je suis en train de développer une application qui intègre une fonction de rêve. Je parle le tutoriel suivant:Impossible de démarrer le service DayDream dans mon application Android personnalisée

http://www.technotalkative.com/how-to-create-daydream/

Sous Paramètres> Affichage> rêvasser, je peux voir mon application dans la liste des applications, mais lorsque je tente de démarrer, rien ne se passe. Je ne suis pas capable de comprendre ce qui ne va pas.

Après mon code en ce qui concerne le même, fichier Manifest:

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <service 
     android:name=".MyDreamService" 
     android:exported="true" 
     android:label="Test - DayDream" > 
     <intent-filter> 
      <action android:name="android.service.dreams.DreamService" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </service> 
</application> 

fichier Classe:

import android.graphics.Color; 
import android.service.dreams.DreamService; 
import android.widget.TextView; 

public class MyDreamService extends DreamService { 
    @Override 
    public void onAttachedToWindow() { 
     super.onAttachedToWindow(); 

     // Allow user touch 
     setInteractive(true); 

     // Hide system UI 
     setFullscreen(true); 

     // Set the dream layout 
     TextView txtView = new TextView(this); 
     setContentView(txtView); 
     txtView.setText("Hello DayDream world from TechnoTalkative.com !!"); 
     txtView.setTextColor(Color.rgb(184, 245, 0)); 
     txtView.setTextSize(30); 

    } 
} 

Répondre

6

Vous ciblez niveau api 21 ou au-dessus. Vous devez définir l'autorisation de service de BIND_DREAM_SERVICE pour répondre à votre rêve éveillé:

<application 
android:allowBackup="true" 
android:icon="@mipmap/ic_launcher" 
android:label="@string/app_name" 
android:supportsRtl="true" 
android:theme="@style/AppTheme"> 
<service 
    android:name=".MyDreamService" 
    android:exported="true" 
    android:label="Test - DayDream" 
    android:permission="android.permission.BIND_DREAM_SERVICE"**> 
    <intent-filter> 
     <action android:name="android.service.dreams.DreamService" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
    </intent-filter> 
</service>