无法在我的自定义 android 应用程序中启动 DayDream 服务
Unable to start DayDream service in my custom android app
我正在尝试开发一款内置白日梦功能的应用程序。我指的是以下教程:
http://www.technotalkative.com/how-to-create-daydream/
在设置>显示>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" >
<intent-filter>
<action android:name="android.service.dreams.DreamService" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
</application>
Class 文件:
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);
}
}
您的目标是 api 21 级或更高级别。您需要设置BIND_DREAM_SERVICE服务权限来完成您的白日梦:
<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>
我正在尝试开发一款内置白日梦功能的应用程序。我指的是以下教程:
http://www.technotalkative.com/how-to-create-daydream/
在设置>显示>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" >
<intent-filter>
<action android:name="android.service.dreams.DreamService" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
</application>
Class 文件:
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);
}
}
您的目标是 api 21 级或更高级别。您需要设置BIND_DREAM_SERVICE服务权限来完成您的白日梦:
<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>