Android based weather Source library for Xiaomi Weather

Source: Internet
Author: User

About this time last year, we shared the application of simple weather. The application started with the Chinese Weather Network data, but because the need to repeatedly request the server to obtain information to meet our needs, so I secretly changed the weather source to "discreet weather" server (if offended, please understand, I just used for learning communication). Because the server has re-processed the weather data we need, including current weather information, forecasts for the next 6 days, air quality, and more. And only need to request the server, the corresponding city name (the simple weather with a database), the link is as follows:

http://sixweather.3gpk.net/SixWeather.aspx?city= Shenzhen &channelid=2177&modelid=4758&deviceid= 352273017386340

(The encoding method is utf-8, note can be)

This allows our application to reduce the number of requests to the server, saving the user valuable traffic. Of course, this kind of stealing the server data resources of the practice is shameful, not recommended for everyone to use! This is for learning and communication only!


recently, I used a millet machine to debug an application, print the log message via a command: adb logcat | grep "Miuiversion", accidentally found the millet weather link exposed to my eyes:

http://weatherapi.market.xiaomi.com/wtr-v2/weather?cityId=101010100&imei=529e2dd3d767bdd3595eec30dd481050 &device=pisces&miuiversion=jxccnbd20.0&moddevice=&source=miuiweatherapp

Hold the mentality of not white, I will this interface re-encapsulated a bit, made a database to get weather data, hope to help you learn.

This weather database has been shared on the Oschina server: Http://git.oschina.net/way/WeatherPlugin

It is also very simple to use:

①. Create a new project and use Weatherplugin as one of his libraries and add network request permissions to the Androidmanifest.xml file:

< uses-permission android:name="Android.permission.INTERNET"/>

②. Get a singleton object by Weatherspiderfactory and pass in a city code (for example, Beijing is: 1010100. In addition I have to put the data of the national 2,500 cities in the assets directory of the example project, please pay attention to view).

③. Calling the Generateweatherinfos () function in an asynchronous thread will request the server and parse the obtained weather data (weather data is supported in three languages: Chinese Simplified, traditional, English, in fact, I also understand these several languages, haha ~).

Weatherspiderfactory factory = Weatherspiderfactory.getinstance (This, "101010100"); final Weatherspiderfactory.ispider spider = Factory.getavailablespiders (); New Thread (New Runnable () {@Overridepublic void Run () {Spider.generateweatherinfos (); LOG.I ("Liweiping", Spider.getalerts (). toString ()); LOG.I ("Liweiping", Spider.getrealtime (). toString ()); LOG.I ("Liweiping", Spider.getaqi (). toString ()); LOG.I ("Liweiping", Spider.getforecast (). toString ()); LOG.I ("Liweiping", Spider.getindex (). toString ());}}). Start ();

The following is the printed log information:


What do you think? Very simple, huh? Other I will not say more, interested can download to see.

Finally, please note that:

I did not strictly test this library, the bug is definitely there, if there are better suggestions, welcome message discussion, Thank you!


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: info-contact@alibabacloud.com 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.