So I am developing an alternate lockscreenapp and 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 invisible Code: 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 Keyguard the 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.
I used full screen before same as your way and had some problems but didn't try launching the activity from service, try to apply full screen this way,
just in case you need to exit full screen, you can do it this way,
give it a shot, good luck!