首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在我的自定义android应用程序中启动DayDream服务

无法在我的自定义android应用程序中启动DayDream服务
EN

Stack Overflow用户
提问于 2016-04-06 07:02:05
回答 1查看 1.6K关注 0票数 4

我正在尝试开发一个应用程序,其中有一个白日梦功能。我指的是以下教程:

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

在Setting>Display>DayDream下,我可以在应用程序列表中看到我的应用程序,但是当我尝试启动它时,什么也不会发生。我无法理解到底出了什么问题。

下面是我关于相同的清单文件的代码:

代码语言:javascript
复制
<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>

类文件:

代码语言:javascript
复制
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);

   }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-27 20:32:59

您的目标是api 21级或以上。您需要设置BIND_DREAM_SERVICE服务权限以实现您的白日梦:

代码语言:javascript
复制
<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>

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36443752

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档