1

所以我正在开发一个备用锁屏应用程序,我需要防止点击通知栏

所以我尝试全屏运行这个应用程序

但是当它被服务调用时,通知栏仍然是他们的,当它被启动器调用时,它会变得不可见代码: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>
4

2 回答 2

0

这似乎this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);导致了这个问题。

其他人建议延迟该呼叫:请参阅Activity doesn't show in full screen

于 2013-08-14T13:46:17.390 回答
0

我之前使用全屏的方式与您的方式相同,但遇到了一些问题,但没有尝试从服务启动活动,尝试以这种方式应用全屏,

WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setAttributes(attrs);

以防万一你需要退出全屏,你可以这样做,

WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setAttributes(attrs);

试一试,祝你好运!

于 2012-05-30T20:14:29.633 回答