Key does not exist. It is also set to exist.

Source: Internet
Author: User

You can use

Android. provider. settings. system. GetType (key); <br/> Android. provider. settings. system. puttype (key ); 

The type can be int, float, string, and so on. The key is a constant defined in Android. provider. settings. system. For example, the following code obtains whether the system's wi-fi connection is enabled for static IP settings:

System. getint (contentresolver, system. wifi_use_static_ip) = 1; 

However, system. GetType (contentresolver, key) functions throw a settingnotfoundexception exception. That is to say, if the value corresponding to this key cannot be found, an exception will be thrown. we should wrap the above Code with try... catch. Of course, system. GetType (contentresolver, key, DEF) may be more convenient in most cases.

In general, this process is not complicated, but if I look into it, why is it impossible to explicitly write the key in the document at runtime? In fact, I have considered this problem before, but I have not thought much about it. I take it for granted that this API design is just "to make it look more rigorous" (now I think about it, how naive I think, haha ). I didn't understand these settings until today.If the initial default value remains unchanged, their corresponding keys will not exist in the system database.! For example, you have not set the static IP Option ("use static IP" is disabled by default) since your phone leaves the factory (or the last time You reinstall the system ), then wifi_use_static_ip does not exist in the system setting database. That is to say, if the key does not exist, it is also a set state of existence.

Of course, there is no possibility of these keys: Some devices do not implement a function. For example, if a mobile phone does not have a Wi-Fi chip or does not support static IP addresses (for example, only), you can also throw a settingnotfoundexception exception (?) When querying wifi_use_static_ip (??). I am very skeptical about this immature point of view.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.