这是交易,我一直致力于制作一个简单的屏幕锁定应用程序,主要执行以下操作:
我已经完成了我的家庭作业并使用了大量链接(特别是在stackoverflow上)并且仍有很多问题
数字1 完美无缺:)
2号有效但不按预期,当我按下它时,它打开要求用户选择家庭应用程序的对话框...我不想要那个!我想制作一个锁屏应用程序,而不是家庭应用程序。 (代码在最后提供)
3号在解锁屏幕之前有效,但在此之后,应用程序不知道如何自动启动。我已经实现了一个广播接收器,它在onCreat()方法的代码中注册了锁屏活动。我认为这是问题所在:S
4号这根本不起作用!
我正在使用某项服务进行测试,但仍无效:'(
清单我确定我使用了正确的权限,是吗?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="himura.test.mylockertest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="9" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<receiver
android:name=".EventsReciever"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.SCREEN_OFF"/>
<action android:name="android.intent.action.SCREEN_ON"/>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<service
android:enabled="true"
android:name=".UpdateService"/>
<activity
android:name=".LockPage"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
活动布局非常简单,只需一个按钮即可解锁:)
public class LockPage extends Activity {
private Button ublockButton;
@Override
public void onAttachedToWindow() {
//this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
super.onAttachedToWindow();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
///** FIRST THINGS FIRST, START THE SERVICE **/
//startService(new Intent(this, myService.class));
/** REGISTERING RECEIVER **/
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_BOOT_COMPLETED);
BroadcastReceiver mReceiver = new EventsReciever();
registerReceiver(mReceiver, filter);
/** SETTING CONTENT VIEW**/
setContentView(R.layout.lockscreen);
/** REMOVING KEYGUARD RECEIVER **/
KeyguardManager keyguardManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.disableKeyguard();
/** NORMAL CODE **/
ublockButton = (Button)findViewById(R.id.bUnlock);
ublockButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});
}
@Override
public void onBackPressed() {
// Don't allow back to dismiss.
return;
}
//only used in lockdown mode
@Override
protected void onPause() {
super.onPause();
Log.i("event","onPause");
// Don't hang around.
finish();
}
@Override
protected void onStop() {
super.onStop();
Log.i("event","onStop");
// Don't hang around.
finish();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return false;
}
}
广播接收器这可以处理3件事,屏幕打开/关闭和启动完成(或它应该),,,我一直在测试日志
public class EventsReciever extends BroadcastReceiver {
//works before unlocking
//after unlocking, keygaurd still off, but receiver has stopped
public static boolean wasScreenOn = true;
@Override
public void onReceive(Context context, Intent recievedIntent) {
Log.i("Check","[BroadCastReciever] onRecieve()");
if (recievedIntent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
wasScreenOn = false;
Log.i("Check","[BroadCastReciever] Screen went OFF");
} else if (recievedIntent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
wasScreenOn = true;
Log.i("Check","[BroadCastReciever] Screen went ON");
Intent intent = new Intent(context, LockPage.class);
context.startActivity(intent);
}
else if(recievedIntent.getAction().equals(Intent.ACTION_BOOT_COMPLETED))
{
Intent intent = new Intent(context, LockPage.class);
context.startActivity(intent);
// Intent intent = new Intent(context, LockPage.class);
// context.startActivity(intent);
// Intent serviceLauncher = new Intent(context, UpdateService.class);
// context.startService(serviceLauncher);
// Log.v("TEST", "Service loaded at start");
}
}
}
最后,服务现在没有做任何事情,我在第一次解锁后试图用它来启动锁定屏幕
public class myService extends Service{
@Override
public void onCreate() {
/** INITIALIZE RECEIVER **/
//RegisterReciever();
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// The standard pattern for implementing a Service is to create and run a new thread from onStartCommand
// to perform the processing in the background and stop the Service when it’s complete
//RegisterReciever();
return Service.START_STICKY;
}
/*private void RegisterReciever(){
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_BOOT_COMPLETED);
BroadcastReceiver mReceiver = new EventsReciever();
registerReceiver(mReceiver, filter);
}*/
}
我在互联网上发现的更多问题包括在打开屏幕后返回状态栏(非常糟糕) 在本机键盘中,有状态栏,但它不起作用,有没有办法做到这一点?
是不是有办法让锁定器活动,并告诉系统你在这里,使用它作为键盘?
答案 0 :(得分:1)
是不是有办法让锁定器活动,并告诉系统你在这里,使用它作为键盘?
如果您创建自己的固件,可能有一种方法可以用替代实现替换键盘,考虑到大多数设备制造商都这样做。您无法通过SDK替换键盘锁。
答案 1 :(得分:1)
解决2号问题(从Home应用程序中删除Lock)从AndroidManifest.xml文件中删除以下行
&LT; category android:name =“android.intent.category.HOME”/&gt;
答案 2 :(得分:0)
服务:
BroadcastReceiver mReceiver=null;
int ReadingBlock = 100;
String PasswordType;
@Override
public void onCreate() {
super.onCreate();
// Register receiver that handles screen on and screen off logic
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
mReceiver = new AutoStart();
registerReceiver(mReceiver, filter);
}
@Override
public void onStart(Intent intent, int startId) {
boolean screenOn = false;
try{
// Get ON/OFF values sent from receiver ( AEScreenOnOffReceiver.java )
screenOn = intent.getBooleanExtra("screen_state", false);
}catch(Exception e){}
if (!screenOn){
} else {
Intent RegularPassword = new Intent(getApplicationContext(), ScreenLock.class);
RegularPassword.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(RegularPassword);
}
}
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onDestroy() {
Log.i("ScreenOnOff", "Service distroy");
if(mReceiver!=null)
unregisterReceiver(mReceiver);
}