问题描述
所以,我开发一个替代lockscreenapp我需要prevent点击notificationbar
所以我尝试运行这个程序在fullscreenn
但是当它是卡莱由服务notificationbar仍然是他们当它被称为发射它得到无形code:公共类的应用程序扩展了活动{
TextView的数据;
静态TextView的时间;
静态TextView的温度;
静态ImageView的weather_icon;
静态的TextView weather_refreshed;
静态RelativeLayout的刷新;
私有静态语境mContext;
/ **第一次创建活动时调用。 * /
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
的setContentView(R.layout.main);
this.startService(新意图(这一点,lockservice.class));
mContext =这一点;
//日期
基准=(TextView中)findViewById(R.id.datum);
SimpleDateFormat的SDF =新的SimpleDateFormat(E DD MMM);
字符串currentDateandTime = sdf.format(新日期());
datum.setText(currentDateandTime);
//时间
时间=(TextView中)findViewById(R.id.clock);
日期日期=新的日期();
INT小时= date.getHours();
字符串diplay_hours =将String.valueOf(小时);
INT分钟= date.getMinutes();
字符串diplay_minutes =将String.valueOf(分钟);
如果(小时小于10)
{
diplay_hours =0+将String.valueOf(小时);
}
如果(分钟小于10)
{
diplay_minutes =0+将String.valueOf(分钟);
}
time.setText(将String.valueOf(diplay_hours +:+ diplay_minutes));
//更新
螺纹myThread =新主题(新UpdateThread());
myThread.start();
// 天气
温度=(TextView中)findViewById(R.id.weather_temp);
weather_icon =(ImageView的)findViewById(R.id.weather_icon);
weather_refreshed =(TextView中)findViewById(R.id.weather_refreshed);
刷新=(RelativeLayout的)findViewById(R.id.relativeLayout1);
refresh.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
weather.download();
}
});
}
@覆盖
公共无效onResume(){
super.onResume();
}
@覆盖
公共无效onAttachedToWindow()
{
。this.getWindow()的setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
@覆盖
公共布尔的onkeydown(INT的iKey code,KeyEvent的事件)
{
如果(iKey的code == KeyEvent.KEY code_BACK ||的iKey code == KeyEvent.KEY code_HOME)
{
完();
返回true;
}
返回false;
}
//更新
公开处理程序updateHandler =新的处理程序(){
/ **被调用的每个接收到的消息* /
// @覆盖
公共无效的handleMessage(信息MSG){
//时间
时间=(TextView中)findViewById(R.id.clock);
日期日期=新的日期();
INT小时= date.getHours();
字符串diplay_hours =将String.valueOf(小时);
INT分钟= date.getMinutes();
字符串diplay_minutes =将String.valueOf(分钟);
如果(小时小于10)
{
diplay_hours =0+将String.valueOf(小时);
}
如果(分钟小于10)
{
diplay_minutes =0+将String.valueOf(分钟);
}
time.setText(将String.valueOf(diplay_hours +:+ diplay_minutes));
//天气
weather.display();
尝试
{
共享preferences天气= app.getContext()getShared preferences(天气,app.getContext()MODE_WORLD_READABLE)。
app.weather_refreshed.setText(weather.getString(时代,));
}
赶上(例外X)
{
}
super.handleMessage(MSG);
}
};
公共类UpdateThread实现Runnable {
@覆盖
公共无效的run(){
而(真){
长的startTime = System.currentTimeMillis的();
app.this.updateHandler.sendEmptyMessage(0); //处理程序
Thread.yield();
尝试 {
视频下载(1000);
}赶上(InterruptedException异常E){
// TODO自动生成的catch块
e.printStackTrace();
}
}
}
}
公共静态上下文的getContext(){
返回mContext;
}
@覆盖
公共无效的onPause(){
super.onPause();
}
我也用键盘保护全屏在我的清单实施的:
<应用
机器人:图标=@可绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME>
<活动
机器人:应用程序名称=
机器人:标签=@字符串/ APP_NAME
机器人:screenOrientation =画像
机器人:主题=@安卓风格/ Theme.NoTitleBar.Fullscreen>
<意向滤光器>
<作用机器人:名称=android.intent.action.MAIN/>
<类机器人:名称=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
<接收器的Android版本:NAME =启动>
<意向滤光器>
<作用机器人:名称=android.intent.action.BOOT_COMPLETED/>
<类机器人:名称=android.intent.category.HOME/>
&所述; /意图滤光器>
< /接收器>
<服务
机器人:名称=lockservice
机器人:工艺=:锁屏
机器人:图标=@可绘制/ ic_launcher
机器人:标签=锁屏>
< /服务>
<活动
机器人:weather_updateNAME =
机器人:主题=@安卓风格/ Theme.Translucent>
< /活性GT;
< /用途>
似乎 this.getWindow()的setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
使问题。
别人建议推迟这一呼吁:请参见活动不会在全屏幕显示。
So I am developing an alternate lockscreenappand I need to prevent clicking the notificationbar
so I try to run this app in fullscreenn
but when it is calle by a service the notificationbar is still their when it is called by the launcher it get invisibleCode:public class app extends Activity {
TextView datum;
static TextView time;
static TextView temperature;
static ImageView weather_icon;
static TextView weather_refreshed;
static RelativeLayout refresh;
private static Context mContext;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
this.startService(new Intent(this, lockservice.class));
mContext = this;
//Date
datum = (TextView) findViewById(R.id.datum);
SimpleDateFormat sdf = new SimpleDateFormat("E dd MMM");
String currentDateandTime = sdf.format(new Date());
datum.setText(currentDateandTime);
//Time
time = (TextView) findViewById(R.id.clock);
Date date = new Date();
int hours = date.getHours();
String diplay_hours = String.valueOf(hours);
int minutes = date.getMinutes();
String diplay_minutes = String.valueOf(minutes);
if(hours < 10)
{
diplay_hours = "0"+String.valueOf(hours);
}
if(minutes < 10)
{
diplay_minutes = "0"+String.valueOf(minutes);
}
time.setText(String.valueOf(diplay_hours+":"+diplay_minutes));
//update
Thread myThread = new Thread(new UpdateThread());
myThread.start();
// Weather
temperature = (TextView) findViewById(R.id.weather_temp);
weather_icon = (ImageView) findViewById(R.id.weather_icon);
weather_refreshed = (TextView) findViewById(R.id.weather_refreshed);
refresh = (RelativeLayout) findViewById(R.id.relativeLayout1);
refresh.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
weather.download();
}
});
}
@Override
public void onResume() {
super.onResume();
}
@Override
public void onAttachedToWindow()
{
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
@Override
public boolean onKeyDown(int iKeyCode, KeyEvent event)
{
if(iKeyCode == KeyEvent.KEYCODE_BACK || iKeyCode == KeyEvent.KEYCODE_HOME)
{
finish();
return true;
}
return false;
}
//update
public Handler updateHandler = new Handler(){
/** Gets called on every message that is received */
// @Override
public void handleMessage(Message msg) {
//Time
time = (TextView) findViewById(R.id.clock);
Date date = new Date();
int hours = date.getHours();
String diplay_hours = String.valueOf(hours);
int minutes = date.getMinutes();
String diplay_minutes = String.valueOf(minutes);
if(hours < 10)
{
diplay_hours = "0"+String.valueOf(hours);
}
if(minutes < 10)
{
diplay_minutes = "0"+String.valueOf(minutes);
}
time.setText(String.valueOf(diplay_hours+":"+diplay_minutes));
//weather
weather.display();
try
{
SharedPreferences weather = app.getContext().getSharedPreferences("weather",app.getContext().MODE_WORLD_READABLE);
app.weather_refreshed.setText(weather.getString("time",""));
}
catch(Exception x)
{
}
super.handleMessage(msg);
}
};
public class UpdateThread implements Runnable {
@Override
public void run() {
while(true){
long startTime = System.currentTimeMillis();
app.this.updateHandler.sendEmptyMessage(0); //handler
Thread.yield();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public static Context getContext(){
return mContext;
}
@Override
public void onPause() {
super.onPause();
}
I also use Keyguardthe fullscreen is implemented in my manifest :
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".app"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="boot">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
<service
android:name="lockservice"
android:process=":lockscreen"
android:icon="@drawable/ic_launcher"
android:label="Lockscreen">
</service>
<activity
android:name=".weather_update"
android:theme="@android:style/Theme.Translucent">
</activity>
</application>
It seems that this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
causes the issue.
Someone else suggests to delay that call: See Activity doesn't show in full screen.
这篇关于当活动由服务推出Android全屏不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!