当前位置:首页 » 安卓系统 » 基于android的天气预报

基于android的天气预报

发布时间: 2024-08-11 12:35:31

‘壹’ 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天气预报开发中的分享功能是怎么实现的

现在的分享基本上都是现成:

  1. android 自带分享功能:虽然比较low,而且不同厂家显示的分享面板可能不一样,但是功能是可以用的,如果要开发写高级功能的那么需要使用到第三方的分享啦

  2. java">/**
    *分享功能
    *
    *@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));
    }
    3. 第三方分享:使用较多的分享->Umeng(友盟),链接:http://www.umeng.com/

    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个城市的天气预报。
(可自定义背景,支持城市全面!)

希望对你有帮助。

热点内容
存储体与MAR 发布:2024-11-25 14:23:08 浏览:282
电脑浏览器怎么取消配置文件 发布:2024-11-25 14:20:39 浏览:163
如何消除服务器数据传输瓶颈 发布:2024-11-25 14:08:48 浏览:288
安卓开发程序如何上传到手机上 发布:2024-11-25 14:08:30 浏览:28
访客qq获取系统源码 发布:2024-11-25 14:08:30 浏览:17
网站如何上传数据库 发布:2024-11-25 14:08:29 浏览:794
怎么操作让安卓手机假装黑屏 发布:2024-11-25 14:07:42 浏览:163
java内部类访问权限 发布:2024-11-25 14:05:59 浏览:342
安卓为什么不分身 发布:2024-11-25 13:54:13 浏览:369
密码锁一般密码是多少 发布:2024-11-25 13:53:37 浏览:73