我创建了一个包含2个活动的应用。一个是设置API密码,另一个是实现登录。如何在Android中将此应用程序作为LockScreen放置?它应该永久运行。
答案 0 :(得分:2)
只是猜测我的
任务1,2,3搜索stackoverflow。他们肯定在那里..
此外,Android中还有用于制作您自己的主屏幕/启动器屏幕的选项。 例如android中的go_launcher app
用于禁用主页密钥试试这个 完整的活动代码是
package com.lockscreen;
import android.app.Activity;
import android.app.KeyguardManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
public class LockScreenActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Activity.KEYGUARD_SERVICE);
KeyguardManager.KeyguardLock lock = keyguardManager
.newKeyguardLock(KEYGUARD_SERVICE);
lock.disableKeyguard();
}
@Override
public void onBackPressed() {
}
@Override
public void onAttachedToWindow() {
// TODO Auto-generated method stub
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add("Exit");
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getTitle().equals("Exit")) {
finish();
System.runFinalizersOnExit(true);
System.exit(0);
}
return super.onOptionsItemSelected(item);
}
}
清单需要许可
<uses-permission
android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>