Android-based weather source library for Xiaomi

Source: Internet
Author: User

At this time last year, I will share with you the simple weather application. This application uses data from www.weather.cn at the beginning. However, we need to repeatedly request the server to obtain information to meet our needs. Therefore, later, I secretly changed the weather source to the "zhiquweather" server (if you have any offense, please forgive me. I am only used for study and communication ). This server re-processes the required weather data, including the current weather information, the forecast for the next six days, and air quality. In addition, you only need to request the server once and input the corresponding city name (a database is provided in simple weather). 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. Pay attention to it)

In this way, our applications can reduce the number of requests to the server and save valuable traffic for users. Of course, this method of stealing data resources from others' servers is shameful and is not recommended! This is only for learning and communication!


Recently, I used Xiaomi's machine to debug an application and run a command to print the log information: adb logcat | grep "miuiVersion ", I accidentally discovered that the link to Xiaomi weather was exposed in front of me:

Http://weatherapi.market.xiaomi.com/wtr-v2/weather? CityId = 101010100 & imei = 529e2dd3d767bdd3595eec30dd481050 & device = pisces & miuiVersion = JXCCNBD20.0 & modDevice = & source = miuiWeatherApp

With the mentality of no need for White, I encapsulated this interface and made it a database for getting weather data, hoping 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:

1. Create a new project, use WeatherPlugin as a library, and add the network request permission to the AndroidManifest. xml file:

<Uses-permissionandroid: name = "android. permission. INTERNET"/>

②. Get a singleton object through WeatherSpiderFactory and pass in the code of a city (for example, Beijing is: 1010100. In addition, I have stored data from 2500 cities across the country in the assets Directory of the example project. Please check it out ).

③. Call the generateWeatherInfos () function in an asynchronous thread to request the server and parse the obtained weather data (weather data can be in simplified Chinese, traditional Chinese, or English, actually, I understand these 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 printed Log information is as follows:


How is it? Is it easy? I will not talk about anything else. If you are interested, please download it.

Note:

I did not strictly test this library, and the bug certainly exists. If you have better suggestions, please leave a message to discuss it. Thank you!


Related Article

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.