基於android的天氣預報
『壹』 android 如何實現獲取天氣預報信息
方法步驟(以安卓5.0為例)
一、打開GPS
九、提示
1.適時刷新天氣需要開啟GPS定位。
2.在沒有WIFI的地方刷新天氣需要消耗一定的流量,刷新頻率越高,消耗流量越多。
『貳』 android端免費獲取天氣信息的伺服器介面有么
中國國家氣象局提供了獲取所在城市天氣預報信息介面。通過這個介面,我們就可以獲取天氣信息了。
關於獲取天氣預報的實例參考android學習手冊,裡面有源碼。android學習手冊包含9個章節,108個例子,源碼文檔隨便看,例子都是可交互,可運行,源碼採用android studio目錄結構,高亮顯示代碼,文檔都採用文檔結構圖顯示,可以快速定位。360手機助手中下載,圖標上有貝殼
中國國家氣象局天氣預報介面總共提供了三個:
http://www.weather.com.cn/data/sk/101010100.html
http://www.weather.com.cn/data/cityinfo/101010100.html
http://m.weather.com.cn/data/101010100.html
註:上面介面2014.3.4日已不再更新。換成這個:http://m.weather.com.cn/atad/101230201.html。各位看34樓。在此感謝tdwll和黃曉佳cobish。
最詳細的信息來自第三個介面。上面url中的101010100是城市代碼,這里是北京的城市代碼。只需要改變城市代碼,就可以得到所在城市的天氣信息。筆者在福州,所以選擇的城市代碼是福州101230101。
在瀏覽器上輸入url:http://m.weather.com.cn/data/101230101.html得到信息,天氣信息是json的數據格式,數據如下:
{"weatherinfo":{"city":"福州","city_en":"fuzhou","date_y":"2012年5月14日","date":"","week":"星期一","fchh":"08","cityid":"101230101","temp1":"29℃~23℃","temp2":"26℃~20℃","temp3":"24℃~20℃","temp4":"25℃~20℃","temp5":"24℃~21℃","temp6":"25℃~22℃","tempF1":"84.2℉~73.4℉","tempF2":"78.8℉~68℉","tempF3":"75.2℉~68℉","tempF4":"77℉~68℉","tempF5":"75.2℉~69.8℉","tempF6":"77℉~71.6℉","weather1":"陣雨轉中雨","weather2":"中雨轉小雨","weather3":"小雨","weather4":"小雨","weather5":"小雨轉陣雨","weather6":"陣雨轉小雨","img1":"3","img2":"8","img3":"8","img4":"7","img5":"7","img6":"99","img7":"7","img8":"99","img9":"7","img10":"3","img11":"3","img12":"7","img_single":"3","img_title1":"陣雨","img_title2":"中雨","img_title3":"中雨","img_title4":"小雨","img_title5":"小雨","img_title6":"小雨","img_title7":"小雨","img_title8":"小雨","img_title9":"小雨","img_title10":"陣雨","img_title11":"陣雨","img_title12":"小雨","img_title_single":"陣雨","wind1":"微風","wind2":"微風","wind3":"微風","wind4":"微風","wind5":"微風","wind6":"微風","fx1":"微風","fx2":"微風","fl1":"小於3級","fl2":"小於3級","fl3":"小於3級","fl4":"小於3級","fl5":"小於3級","fl6":"小於3級","index":"熱","index_d":"天氣較熱,建議著短裙、短褲、短套裝、T恤等夏季服裝。年老體弱者宜著長袖襯衫和單褲。","index48":"暖","index48_d":"較涼爽,建議著長袖襯衫加單褲等春秋過渡裝。年老體弱者宜著針織長袖襯衫、馬甲和長褲。","index_uv":"弱","index48_uv":"最弱","index_xc":"不宜","index_tr":"適宜","index_co":"較不舒適","st1":"27","st2":"21","st3":"24","st4":"18","st5":"22","st6":"18","index_cl":"較不宜","index_ls":"不太適宜","index_ag":"不易發"}}
我們可以解析json數據去得到自己想用的天氣信息。
天氣信息解釋:
[html] view plain print?
{
"weatherinfo":{
<!--基本信息-->
"city":"福州",
"city_en":"fuzhou",
"date_y":"2012年5月14日",
"date":"",
"week":"星期一",
"fchh":"08",
"cityid":"101230101",
<!--從今天開始到第六天的每天的天氣情況,這里的溫度是攝氏溫度-->
"temp1":"29℃~23℃","temp2":"26℃~20℃","temp3":"24℃~20℃","temp4":"25℃~20℃","temp5":"24℃~21℃","temp6":"25℃~22℃",
<!--從今天開始到第六天的每天的天氣情況,這里的溫度是華氏溫度-->
"tempF1":"84.2℉~73.4℉","tempF2":"78.8℉~68℉","tempF3":"75.2℉~68℉","tempF4":"77℉~68℉","tempF5":"75.2℉~69.8℉","tempF6":"77℉~71.6℉",
<!--天氣描述-->
"weather1":"陣雨轉中雨","weather2":"中雨轉小雨","weather3":"小雨","weather4":"小雨","weather5":"小雨轉陣雨","weather6":"陣雨轉小雨",
<!--天氣描述圖片序號-->
"img1":"3","img2":"8","img3":"8","img4":"7","img5":"7","img6":"99","img7":"7","img8":"99","img9":"7","img10":"3","img11":"3","img12":"7","img_single":"3",
<!--圖片名稱-->
"img_title1":"陣雨","img_title2":"中雨","img_title3":"中雨","img_title4":"小雨","img_title5":"小雨","img_title6":"小雨","img_title7":"小雨","img_title8":"小雨","img_title9":"小雨","img_title10":"陣雨","img_title11":"陣雨","img_title12":"小雨","img_title_single":"陣雨",
<!--風速描述-->
"wind1":"微風","wind2":"微風","wind3":"微風","wind4":"微風","wind5":"微風","wind6":"微風","fx1":"微風","fx2":"微風",
<!--風速級別描述-->
"fl1":"小於3級","fl2":"小於3級","fl3":"小於3級","fl4":"小於3級","fl5":"小於3級","fl6":"小於3級",
<!--今天穿衣指數-->
"index":"熱",
"index_d":"天氣較熱,建議著短裙、短褲、短套裝、T恤等夏季服裝。年老體弱者宜著長袖襯衫和單褲。",
<!--48小時穿衣指數-->
"index48":"暖","index48_d":"較涼爽,建議著長袖襯衫加單褲等春秋過渡裝。年老體弱者宜著針織長袖襯衫、馬甲和長褲。",
<!--紫外線及48小時紫外線-->
"index_uv":"弱","index48_uv":"最弱",
<!--洗車-->
"index_xc":"不宜",
<!--旅遊-->
"index_tr":"適宜",、
<!--舒適指數-->
"index_co":"較不舒適",
"st1":"27","st2":"21","st3":"24","st4":"18","st5":"22","st6":"18",
<!--晨練-->
"index_cl":"較不宜",
<!--晾曬-->
"index_ls":"不太適宜",
<!--過敏-->
"index_ag":"不易發"
}
}
{
"weatherinfo":{
<!-- 基本信息 -->
"city":"福州",
"city_en":"fuzhou",
"date_y":"2012年5月14日",
"date":"",
"week":"星期一",
"fchh":"08",
"cityid":"101230101",
<!-- 從今天開始到第六天的每天的天氣情況,這里的溫度是攝氏溫度 -->
"temp1":"29℃~23℃","temp2":"26℃~20℃","temp3":"24℃~20℃","temp4":"25℃~20℃","temp5":"24℃~21℃","temp6":"25℃~22℃",
<!-- 從今天開始到第六天的每天的天氣情況,這里的溫度是華氏溫度 -->
"tempF1":"84.2℉~73.4℉","tempF2":"78.8℉~68℉","tempF3":"75.2℉~68℉","tempF4":"77℉~68℉","tempF5":"75.2℉~69.8℉","tempF6":"77℉~71.6℉",
<!-- 天氣描述 -->
"weather1":"陣雨轉中雨","weather2":"中雨轉小雨","weather3":"小雨","weather4":"小雨","weather5":"小雨轉陣雨","weather6":"陣雨轉小雨",
<!-- 天氣描述圖片序號 -->
"img1":"3","img2":"8","img3":"8","img4":"7","img5":"7","img6":"99","img7":"7","img8":"99","img9":"7","img10":"3","img11":"3","img12":"7","img_single":"3",
<!-- 圖片名稱 -->
"img_title1":"陣雨","img_title2":"中雨","img_title3":"中雨","img_title4":"小雨","img_title5":"小雨","img_title6":"小雨","img_title7":"小雨","img_title8":"小雨","img_title9":"小雨","img_title10":"陣雨","img_title11":"陣雨","img_title12":"小雨","img_title_single":"陣雨",
<!-- 風速描述 -->
"wind1":"微風","wind2":"微風","wind3":"微風","wind4":"微風","wind5":"微風","wind6":"微風","fx1":"微風","fx2":"微風",
<!-- 風速級別描述 -->
"fl1":"小於3級","fl2":"小於3級","fl3":"小於3級","fl4":"小於3級","fl5":"小於3級","fl6":"小於3級",
<!-- 今天穿衣指數 -->
"index":"熱",
"index_d":"天氣較熱,建議著短裙、短褲、短套裝、T恤等夏季服裝。年老體弱者宜著長袖襯衫和單褲。",
<!-- 48小時穿衣指數 -->
"index48":"暖","index48_d":"較涼爽,建議著長袖襯衫加單褲等春秋過渡裝。年老體弱者宜著針織長袖襯衫、馬甲和長褲。",
<!-- 紫外線及48小時紫外線 -->
"index_uv":"弱","index48_uv":"最弱",
<!-- 洗車 -->
"index_xc":"不宜",
<!-- 旅遊 -->
"index_tr":"適宜",、
<!-- 舒適指數 -->
"index_co":"較不舒適",
"st1":"27","st2":"21","st3":"24","st4":"18","st5":"22","st6":"18",
<!-- 晨練 -->
"index_cl":"較不宜",
<!-- 晾曬 -->
"index_ls":"不太適宜",
<!-- 過敏 -->
"index_ag":"不易發"
}
}
『叄』 基於android天氣預報開發中的分享功能是怎麼實現的
現在的分享基本上都是現成:
android 自帶分享功能:雖然比較low,而且不同廠家顯示的分享面板可能不一樣,但是功能是可以用的,如果要開發寫高級功能的那麼需要使用到第三方的分享啦
java">/**
3. 第三方分享:使用較多的分享->Umeng(友盟),鏈接:http://www.umeng.com/
*分享功能
*
*@paramcontext上下文
*@paramactivityTitleActivity的名字
*@parammsgTitle消息標題
*@parammsgText消息內容
*@paramimgPath圖片路徑,不分享圖片則傳null
*/
publicvoidshareMsg(StringactivityTitle,StringmsgTitle,StringmsgText,
StringimgPath){
Intentintent=newIntent(Intent.ACTION_SEND);
if(imgPath==null||imgPath.equals("")){
intent.setType("text/plain");//純文本
}else{
Filef=newFile(imgPath);
if(f!=null&&f.exists()&&f.isFile()){
intent.setType("image/jpg");
Uriu=Uri.fromFile(f);
intent.putExtra(Intent.EXTRA_STREAM,u);
}
}
intent.putExtra(Intent.EXTRA_SUBJECT,msgTitle);
intent.putExtra(Intent.EXTRA_TEXT,msgText);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(intent,activityTitle));
}4. 第三方分享:使用較多的分享->ShareSDK ,鏈接:http://www.mob.com/
『肆』 android天氣預報控制項省份和城市怎麼實例化
使用Intent載入天氣預報數據的服務,代碼如下:
intent=newIntent(LoadUI.this,LoadDataService.class);
Bundlebundle=newBundle();//創建天氣內容
bundle.putString("city",WeatherUtil.getDefaultCity(LoadUI.this));
bundle.putBoolean("check",false);//不編寫內容
intent.putExtras(bundle);//封裝天氣
LoadUI.this.startService(LoadUI.this.intent);
LoadDataService類是用於載入天氣預報數據的服務類,這個類需要做以下幾件事情:
city=URLEncoder.encode(city,"UTF-8");
『伍』 手機是聯通的Android系統,有沒有天氣預報方面的軟體
天氣預報方面的軟體有很多,天氣秀、天氣通等,Android系統的手機(包含聯通定製機)推薦使用「墨跡天氣」。
墨跡天氣是一款桌面天氣軟體,預報准確,覆蓋城市廣,流量少,界面華麗。下載「墨跡天氣」軟體信息費完全免費,流量費由運營商收取。
聯通定製手機可以通過http://wap.mojichina.com下載。
『陸』 Android涓婄殑澶╂皵棰勬姤杞浠跺摢涓鍑嗕竴鐐瑰憖 璋㈣阿
鍦ˋndroid騫沖彴涓婏紝閫夋嫨涓涓鍑嗙『鐨勫ぉ姘旈勬姤杞浠舵槸寰堥噸瑕佺殑銆備互涓嬫槸涓浜涚敤鎴鋒帹鑽愮殑搴旂敤錛屽畠浠鍦ㄥ噯紜鎬у拰鍔熻兘涓婂悇鏈夌壒鑹詫細
1. 澧ㄨ抗澶╂皵錛氳繖嬈捐蔣浠跺洜鍏跺噯紜鐨勯勬姤銆佸箍娉涚殑鍩庡競瑕嗙洊浠ュ強鑺傛祦鐨勭壒鐐硅屽彈鍒板ソ璇勩傚畠鐨勭晫闈㈣捐$簿緹庯紝騫朵笖鏀鎸佽闊蟲挱鎶ュぉ姘旓紝鎻愪緵涓板瘜鐨勭毊鑲よ祫婧愩
2. GO澶╂皵錛欸O澶╂皵浠ョ偒閰風殑鐣岄潰鍜屽疄鏃跺ぉ姘旈勬姤钁楃О錛岃兘澶熸煡鐪嬪叏鐞冧富瑕佸煄甯傜殑澶╂皵淇℃伅銆傞氳繃璁塊棶鍏ㄧ悆鏁頒竾涓鍦板尯鐨勪笓涓氬ぉ姘旂綉錛屽畠鑳藉湪浠諱綍鏃墮棿銆佷換浣曞湴鐐規彁渚涚簿紜鐨勫ぉ姘斾俊鎮銆傝繖嬈懼簲鐢ㄧ敱Go鍥㈤槦寮鍙戱紝鏀鎸侀珮娓呭ぉ姘旇嗛戱紝闈炲父鍗庝附銆
3. MIUI澶╂皵錛氳繖嬈劇敱MIUI寮鍙戠殑澶╂皵杞浠訛紝鐣岄潰鏃跺皻澶ф柟錛屽姛鑳藉己澶с傚畠鏀鎸佸叏鍥藉氫釜鍩庡競錛屽寘鎷鍛ㄨ竟鍩庡競鐨勫ぉ姘旈勬姤錛屽苟鎻愪緵澶╂皵鎻愰啋鍜屾薄鏌撴寚鏁扮瓑鍔熻兘銆侻IUI澶╂皵鐨勯珮娓呯毊鑲ゅ拰鍔ㄦ佸ぉ姘旀晥鏋滃皢鎻愪緵鍗庝附鐨勮嗚変綋楠屻
4. 澶╂皵閫氾細榪欐槸涓嬈懼厤璐圭殑鎵嬫満澶╂皵棰勬姤杞浠訛紝鎻愪緵鐩磋傜殑鍥炬枃澶╂皵鏄劇ず鍜岃﹀敖鐨勫煄甯傜洰褰曘傚畠鏀鎸佸氫釜棰勬姤緗戠珯錛屽苟閫氳繃緗戠粶鑾峰彇澶╂皵淇℃伅錛岀晫闈㈠吀闆咃紝鍔熻兘鍏ㄩ潰銆傛ゅ栵紝瀹冭繕鎻愪緵鍏ㄥ睆鍔ㄧ敾鍜岀嫭鐗圭殑鏃ュ巻澶囨敞鍔熻兘銆
5. 鍗庝附鍔ㄦ佸ぉ姘旓紙Animated Weather錛夛細榪欐懼簲鐢ㄧ▼搴忎負鐢ㄦ埛鎻愪緵姣忔棩鐨勫姩鎬佸ぉ姘旈勬姤錛屽叿鏈夐肩湡鐨勫姩鎬佸ぉ姘旂壒鏁堝拰鑷瀹氫箟鑳屾櫙鍔熻兘銆傚畠鏀鎸佸叏鐞冭秴榪50000涓鍩庡競鐨勫ぉ姘旈勬姤錛岀敤鎴峰彲浠ユ牴鎹涓浜哄枩濂借嚜瀹氫箟鑳屾櫙銆
浠ヤ笂杞浠跺悇鏈夊崈縐嬶紝浣犲彲浠ユ牴鎹鑷宸辯殑闇奼傞夋嫨鏈閫傚悎鐨勫ぉ姘旈勬姤搴旂敤銆傚笇鏈涜繖浜涘緩璁瀵逛綘鏈夋墍甯鍔┿
『柒』 Android上的天氣預報軟體哪個准一點呀 謝謝
單以預報准確而言,個人最為推薦墨跡天氣。一直在用,感覺很好。
1.墨跡天氣
墨跡天氣是一款以預報准確,覆蓋城市廣,流量少,界面華麗等為特點的桌面天氣軟體。
(支持語音播報天氣,皮膚資源也非常豐富!)
另外還有幾款好的軟體,各有所長吧。
2.GO天氣
GO天氣是一款華麗炫酷的實時天氣預報軟體,可查看全球主要城市的天氣。通過訪問美國及全世界數萬個地區中的最大的專業天氣網,GO天氣在任何時間任何地點,都可以獲得最精確的天氣信息。(Go團隊出品,支持高清天氣視頻,十分華麗!)
3.MIUI天氣
一款MIUI開發的天氣軟體,界面時尚大方美觀,功能強大,支持全國城市,支持周邊城市天氣預報,支持天氣提醒,支持污染指數等功能。
(提取自MIUI固件,高清皮膚,天氣效果動態顯示,給你最華麗的體驗!)
4.天氣通
天氣通是一款免費手機天氣預報軟體。通過網路獲取天氣信息,以直觀的圖文方式顯示,詳盡的城市目錄,支持多個預報網站。桌面圖標典雅,天氣網標則充滿新意。
(功能全面,支持全屏動畫,還有獨特的日歷備注功能!)
5.華麗動態天氣
Animated Weather是Android手機上的天氣預報應用程序,每日動態天氣預報,逼真的動態天氣特效,自定義背景,支持世界超過50000個城市的天氣預報。
(可自定義背景,支持城市全面!)
希望對你有幫助。