android里设置screentimeout

news/2024/7/4 0:53:58 标签: android, layout, encoding, application, class, button
class="baidu_pl">
class="article_content clearfix">
class="htmledit_views">

最近在修改class="tags" href="/tags/ANDROID.html" title=android>android的锁屏时间,发现在settings里只有读写数据库的接口,却没发现这些值究竟是怎么起作用的

最后全局搜索,才发现会在phonewindow里用ContentObserver来对setting.db做监听

测试了个小APK来验证,证实是这样的

附件中为具体源码(附件后缀要修改rar),下面贴出来如下:

ContentobserveActivity.java

 

package com.class="tags" href="/tags/ANDROID.html" title=android>android;
import class="tags" href="/tags/ANDROID.html" title=android>android.app.Activity;
import class="tags" href="/tags/ANDROID.html" title=android>android.content.ContentResolver;
import class="tags" href="/tags/ANDROID.html" title=android>android.database.ContentObserver;
import class="tags" href="/tags/ANDROID.html" title=android>android.os.Bundle;
import class="tags" href="/tags/ANDROID.html" title=android>android.os.Handler;
import class="tags" href="/tags/ANDROID.html" title=android>android.provider.Settings;
import class="tags" href="/tags/ANDROID.html" title=android>android.util.Log;
import class="tags" href="/tags/ANDROID.html" title=android>android.view.View;
import class="tags" href="/tags/ANDROID.html" title=android>android.view.View.OnClickListener;
import class="tags" href="/tags/ANDROID.html" title=android>android.widget.EditText;

public class ContentobserveActivity extends Activity implements OnClickListener {
 
 String TAG="sano";
 
 Handler mHandler;
 
 SettingsObserver Observer;
 
 private EditText eSetting;
 
 private EditText eShow;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.class="tags" href="/tags/LAYOUT.html" title=layout>layout.main);
       
        init_ui();
       
        mHandler = new Handler();
       
        Observer =new SettingsObserver(mHandler);
        Observer.registerobserves();
       
    }
   
    public void init_ui(){
     eSetting = (EditText) findViewById(R.id.editText1);
     eShow = (EditText) findViewById(R.id.editText2);
     
     findViewById(R.id.button1).setOnClickListener(this);
    }
   
   
    class SettingsObserver extends ContentObserver {

  @Override
  public boolean deliverSelfNotifications() {
   
   Log.d(TAG,"deliverSelfNotifications");
   return super.deliverSelfNotifications();
  }

  @Override
  public void onChange(boolean selfChange) {
   Log.d(TAG,"onChange");
   
   
  }

  SettingsObserver(Handler handler) {
            super(handler);
        }

  
  public void registerobserves(){
   Log.d(TAG,"registerobserves");
   
       ContentResolver resolver = getContentResolver();
          resolver.registerContentObserver(Settings.System.getUriFor(Settings.System.SCREEN_OFF_TIMEOUT), false, this);
  }
     
    }


 @Override
 public void onClick(View v) {
  
  Log.d(TAG,"write "+eSetting.getText().toString());
        Settings.System.putInt(getContentResolver(),Settings.System.SCREEN_OFF_TIMEOUT, Integer.parseInt(eSetting.getText().toString()));
 }
}

 

 

main.xml

 

<?xml version="1.0" class="tags" href="/tags/ENCODING.html" title=encoding>encoding="utf-8"?>
<LinearLayout xmlns:class="tags" href="/tags/ANDROID.html" title=android>android="http://schemas.class="tags" href="/tags/ANDROID.html" title=android>android.com/apk/res/class="tags" href="/tags/ANDROID.html" title=android>android"
    class="tags" href="/tags/ANDROID.html" title=android>android:class="tags" href="/tags/LAYOUT.html" title=layout>layout_width="match_parent"
    class="tags" href="/tags/ANDROID.html" title=android>android:class="tags" href="/tags/LAYOUT.html" title=layout>layout_height="match_parent"
    class="tags" href="/tags/ANDROID.html" title=android>android:baselineAligned="false"
    class="tags" href="/tags/ANDROID.html" title=android>android:orientation="vertical" >

    <TextView
        class="tags" href="/tags/ANDROID.html" title=android>android:id="@+id/textView1"
        class="tags" href="/tags/ANDROID.html" title=android>android:class="tags" href="/tags/LAYOUT.html" title=layout>layout_width="wrap_content"
        class="tags" href="/tags/ANDROID.html" title=android>android:class="tags" href="/tags/LAYOUT.html" title=layout>layout_height="wrap_content"
        class="tags" href="/tags/ANDROID.html" title=android>android:text="设置系统锁屏时间" />
    <EditText
        class="tags" href="/tags/ANDROID.html" title=android>android:id="@+id/editText1"
        class="tags" href="/tags/ANDROID.html" title=android>android:class="tags" href="/tags/LAYOUT.html" title=layout>layout_width="244dp"
        class="tags" href="/tags/ANDROID.html" title=android>android:class="tags" href="/tags/LAYOUT.html" title=layout>layout_height="wrap_content" >
    </EditText>

    <Button
        class="tags" href="/tags/ANDROID.html" title=android>android:id="@+id/button1"
        class="tags" href="/tags/ANDROID.html" title=android>android:class="tags" href="/tags/LAYOUT.html" title=layout>layout_width="wrap_content"
        class="tags" href="/tags/ANDROID.html" title=android>android:class="tags" href="/tags/LAYOUT.html" title=layout>layout_height="wrap_content"
        class="tags" href="/tags/ANDROID.html" title=android>android:text="设置" />

    <EditText
        class="tags" href="/tags/ANDROID.html" title=android>android:id="@+id/editText2"
        class="tags" href="/tags/ANDROID.html" title=android>android:class="tags" href="/tags/LAYOUT.html" title=layout>layout_width="match_parent"
        class="tags" href="/tags/ANDROID.html" title=android>android:class="tags" href="/tags/LAYOUT.html" title=layout>layout_height="wrap_content" />

</LinearLayout>

 

AndroidManifest.xml

<?xml version="1.0" class="tags" href="/tags/ENCODING.html" title=encoding>encoding="utf-8"?>
<manifest xmlns:class="tags" href="/tags/ANDROID.html" title=android>android="http://schemas.class="tags" href="/tags/ANDROID.html" title=android>android.com/apk/res/class="tags" href="/tags/ANDROID.html" title=android>android"
    package="com.class="tags" href="/tags/ANDROID.html" title=android>android"
    class="tags" href="/tags/ANDROID.html" title=android>android:versionCode="1"
    class="tags" href="/tags/ANDROID.html" title=android>android:versionName="1.0" >

    <uses-sdk class="tags" href="/tags/ANDROID.html" title=android>android:minSdkVersion="9" />
  
    <uses-permission class="tags" href="/tags/ANDROID.html" title=android>android:name="class="tags" href="/tags/ANDROID.html" title=android>android.permission.WRITE_SETTINGS" />
  <uses-permission class="tags" href="/tags/ANDROID.html" title=android>android:name="class="tags" href="/tags/ANDROID.html" title=android>android.permission.WRITE_SECURE_SETTINGS" />
    <class="tags" href="/tags/APPLICATION.html" title=application>application
        class="tags" href="/tags/ANDROID.html" title=android>android:icon="@drawable/ic_launcher"
        class="tags" href="/tags/ANDROID.html" title=android>android:label="@string/app_name" >
        <activity
            class="tags" href="/tags/ANDROID.html" title=android>android:label="@string/app_name"
            class="tags" href="/tags/ANDROID.html" title=android>android:name=".ContentobserveActivity" >
            <intent-filter >
                <action class="tags" href="/tags/ANDROID.html" title=android>android:name="class="tags" href="/tags/ANDROID.html" title=android>android.intent.action.MAIN" />

                <category class="tags" href="/tags/ANDROID.html" title=android>android:name="class="tags" href="/tags/ANDROID.html" title=android>android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </class="tags" href="/tags/APPLICATION.html" title=application>application>

</manifest>

 

 


http://www.niftyadmin.cn/n/1743442.html

相关文章

java里public/private/protected权限关系

用一个图标来表示,相信大家一看就明白 要注意的主要在protected在包外的时候,new出来的新对象是无法访问的。 本类 包内其它类 包外其它类 派生 对象 派生 对象 public √ √ √ √ √ protected √ √ √ √ X private √ X X X X

详解android的screentimeout机制

前一次的博文只是对如何监听settings里的screentimeout做了解释,而具体是如何实现系统睡眠并为做详细说明,近来有对此做休整,所以重温下具体实现. 1.设置里为何只有保存数据,而并没有保存后的数值对系统的影响? ——>displaysettings.java Override protected void onC…

c语言指针注意事项

这几天对C语言的指针温习了下,感觉理解又更深入了一步 C语言的精髓是指针我想确实一点都不错,但是在使用的时候有很多要注意的地方,大概总结一下: 1.指针指向常量区,是不能修改其值的 比如: char *p "abcfd"; char *ptr "abcfd"; *(p1) C; //此时会…

Linux ftrace使用

https://linux.cn/article-9273-1.html

C语言注意点

http://blog.csdn.net/In_No_Vation/article/details/79022711

Linux内核模块开发之helloworld

第一步、编写helloworld.c #include <linux/init.h> //所有模块都必须包含的头文件 #include <linux/module.h> //一些宏定义&#xff0c;例如这里的KERN_INFO#define DRIVER_AUTHOR "xzvi-chip.com.cn"#define DRIVER_DESC "A sample driver&quo…

拿着地图学Python(00)——学习一门新的编程语言需要重点掌握什么?

作为一名合格的程序员只掌握一门编程语言是远远不够的。一门编程语言背后承载的是它的设计哲学和它背后的程序设计思想&#xff0c;多学习一门编程语言就多了一支描绘世界的笔。 入门一门编程语言还是比较简单的&#xff0c;进阶则需要大量的练习&#xff0c;甚至是经历各种大型…