所以我正在开发一个备用锁屏应用程序,我需要防止点击通知栏
所以我尝试全屏运行这个应用程序
但是当它被服务调用时,通知栏仍然是他们的,当它被启动器调用时,它会变得不可见代码: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();
}
我还使用 Keyguard 在我的清单中实现全屏:
<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>