我希望我的应用能够打开屏幕并显示我的应用程序.假设我正在设置闹钟,每小时我都希望我的应用在设备自然睡眠前显示2分钟.
我看到不推荐使用WakeLock(FULL_LOCK)和KeyguardManager.
我创建了一个WakefulBroadcastReceiver和服务,这些都在工作.
@Override
protected void onHandleIntent(Intent intent) {
// I need to show the screen here!
for (int i=0; i<5; i++) {
Log.i("SimpleWakefulReceiver", "Running service " + (i + 1)
+ "/5 @ " + SystemClock.elapsedRealtime());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
}
Log.i("SimpleWakefulReceiver", "Completed service @ " +
SystemClock.elapsedRealtime());
SimpleWakefulReceiver.completeWakefulIntent(intent);
}
Run Code Online (Sandbox Code Playgroud)
如何以编程方式打开屏幕,过去锁定并从IntentService显示我的活动?
谢谢
我有一个作为Web服务器运行的应用程序.该应用程序有一个START_STICKY服务我希望此服务始终运行Web服务器(选项在通知中提供给用户以停止它).
问题是当我滑动我的应用程序关闭时服务器重新启动(丢失设置等).它保持良好,但logcat显示它正在重新启动.
我可以重新打开我的应用程序并绑定到新服务,这很好.虽然再次滑动关闭具有相同的效果.
我需要这个不要重启.
标准服务代码
private WebServerService mService;
private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className,
IBinder binder) {
WebServerService.MyBinder b = (WebServerService.MyBinder) binder;
mService = b.getService();
}
public void onServiceDisconnected(ComponentName className) {
mService = null;
}
};
public serviceStart() {
mIntent = new Intent(mContext.getApplicationContext(), WebServerService.class);
mContext.startService(mIntent);
mContext.bindService(mIntent, mConnection, Context.BIND_AUTO_CREATE);
}
Run Code Online (Sandbox Code Playgroud)
服务开始
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, START_STICKY, startId);
Log.d("SERVICE","Started");
return START_STICKY;
}
Run Code Online (Sandbox Code Playgroud) 我已关注http://www.youtube.com/watch?v=pdUcANNm72o并为我的应用设置了设置.
我有10个布尔出现了.这可以在调用的配置文件中设置.
然而,它们没有勾选/未勾选,然后所有者返回设置,它们已恢复为默认值.
1 /系统是否意味着知道哪个用户已经选择了哪些设置,或者我打算在GetRestrictionsReceiver中打勾或取消勾选.如果我是,我的意思是如何将每个用户设置视为
Bundle restrictionsBundle = ((UserManager) getSystemService(Context.USER_SERVICE)).getApplicationRestrictions(getPackageName());
restrictionsBundle.getBoolean("....
Run Code Online (Sandbox Code Playgroud)
适用于用户登录的时间!?
2 /这是一个错误吗?
提前致谢.