Android源码去除锁屏及应用程序开机自动运行不锁屏全屏显示

来源:互联网 发布:2015双十一数据分析 编辑:程序博客网 时间:2024/06/07 04:43

转载自:http://xiangxingchina.iteye.com/blog/1739303

针对RealV210提供的源码 android_gingerbread_realv210_ver_1_2   2.3.1 

设置默认锁屏时间 

frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java 
private void loadSystemSettings(SQLiteDatabase db) { 
loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT, 
                     R.integer.def_screen_off_timeout); 
frameworks/base/packages/SettingsProvider/res/values/defaults.xml 
<integer name="def_screen_off_timeout">-1</integer> 
以毫秒为单位,设为-1即可,重新编译Setting Provider模块 
但是只是这样修改的话,启动后依旧会进入锁屏状态,解锁之后就再也不会锁屏了 

开机不锁屏 
frameworks/base/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java 
     /** 
      * External apps (like the phone app) can tell us to disable the keygaurd. 
      */ 
     private boolean mExternallyEnabled = true; 
改为false 
$ source build/envsetup.sh 
$ mmm frameworks/base/policy/ 
Install: out/target/product/generic/data/app/FrameworkPolicyTests.apk 
为了打开锁屏功能,可调用函数setKeyguardEnabled() 





应用程序开机自动运行 

新建文件 
public class AutoBoot extends BroadcastReceiver { 
@Override 
public void onReceive(Context arg0, Intent arg1) { 
if (arg1.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { 
Intent helloActivityIntent = new Intent(arg0, HelloActivity.class); 
helloActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
arg0.startActivity(helloActivityIntent); 



修改AndroidManifest.xml 
在<application>中加入(AutoBoot为上面的类名) 
<receiver android:name=".AutoBoot"> 
             <intent-filter> 
                 <action android:name="android.intent.action.BOOT_COMPLETED" /> 
<category android:name="android.intent.category.HOME" /> 
             </intent-filter> 
         </receiver> 
加入 
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 


应用程序开机不锁屏 

<uses-permission android:name="android.permission.DISABLE_KEYGUARD" /> 
onCreate中加入,最好在setContentView(R.layout.main)之前 
getWindow().setFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD, 
         WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); 
         getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, 
         WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 


应用程序全屏显示 
在配置文件的<application>中加入 
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
应用程序部分摘自http://www.cnblogs.com/ikakawa/archive/2011/08/30/2159418.html 

0 0