所以我正在開發一個替代lockscreenapp 推出,我需要防止點擊notificationbar的Android全屏幕不能正常工作時,活動由服務
所以我儘量在fullscreenn
但是,當運行這個程序它是大道由notificationbar仍然是他們當它被髮射稱之爲得到無形 代碼服務: 公共類的應用程序擴展活動{
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();
}
我也用鍵盤鎖 全屏在我的清單中實現:
<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>
它適用於正常啓動,但在通過服務啓動後,通知欄仍然存在,但無論如何感謝 – user1426956