Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to start DayDream service in my custom android app

I am trying to develop an app which has a daydream feature built in it. I am referring the following tutorial:

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

Under Setting>Display>DayDream, I am able to see my application in the list of apps but when I try to start it, nothing happens. I am not able to understand what is going wrong.

Following is my code regarding the same, Manifest file:

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

Class file:

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

   }
}
like image 712
Kunal Chaubal Avatar asked Jan 06 '23 08:01

Kunal Chaubal


1 Answers

You are targeting api level 21 or above. You need to set the BIND_DREAM_SERVICE service permission to fulfill your daydream:

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

like image 63
Hans-J. Schmid Avatar answered Feb 24 '23 16:02

Hans-J. Schmid