android天气开发
❶ 基于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开发天气预报代码运行的时候老是报错,图片如下:
Log说的很清楚了,MainActivity第55行报NullPointerException,看看你代码的55行是什么,错误应该是出在WebService返回的结果,你没有对返回的List做非空判断就用这个List去初始化适配器了
另外,调用WebService的操作应该放在线程里执行,你的写法如果网速慢直接卡住界面了
❸ 求Android天气预报的开发源代码
package com.nrzc.weatherstation;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import java.util.Timer;
import java.util.TimerTask;
/**
* 环境传感器
* 气象站
*/
public class MainActivity extends AppCompatActivity {
private SensorManager sensorManager;
private TextView temperatureTextView;
private TextView pressureTextView;
private TextView lightTextView;
private float currentTemperature=Float.NaN;
private float currentPressure=Float.NaN;
private float currentLight=Float.NaN;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
Timer updateTimer=new Timer("weatherUpdate");
updateTimer.scheleAtFixedRate(new TimerTask() {
@Override
public void run() {
updateGUI();
}
},0,1000);
}
private void init(){
temperatureTextView=(TextView)findViewById(R.id.temperature);
pressureTextView=(TextView)findViewById(R.id.pressure);
lightTextView=(TextView)findViewById(R.id.light);
sensorManager=(SensorManager)getSystemService(Context.SENSOR_SERVICE);
}
private final SensorEventListener tempSensorEventListener=new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
currentTemperature=event.values[0];
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
private final SensorEventListener pressureSensorEventListener=new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
currentPressure=event.values[0];
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
private final SensorEventListener lightSensorEventListener=new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
currentLight=event.values[0];
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
@Override
protected void onResume() {
super.onResume();
Sensor lightSensor=sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
if (lightSensor!=null)
sensorManager.registerListener(lightSensorEventListener,
lightSensor,
SensorManager.SENSOR_DELAY_NORMAL);
else
lightTextView.setText("Light Sensor Unavailable");
Sensor pressureSensor=sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
if (pressureSensor!=null)
sensorManager.registerListener(pressureSensorEventListener,
pressureSensor,SensorManager.SENSOR_DELAY_NORMAL);
else
pressureTextView.setText("Barometer Unavailable");
Sensor temperatureSensor=sensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE);
if (temperatureSensor!=null)
sensorManager.registerListener(tempSensorEventListener,
temperatureSensor,
SensorManager.SENSOR_DELAY_NORMAL);
else
temperatureTextView.setText("Thermometer Unavailable");
}
@Override
protected void onPause() {
sensorManager.unregisterListener(pressureSensorEventListener);
sensorManager.unregisterListener(tempSensorEventListener);
sensorManager.unregisterListener(lightSensorEventListener);
super.onPause();
}
private void updateGUI(){
runOnUiThread(new Runnable() {
@Override
public void run() {
if(!Float.isNaN(currentPressure)){
pressureTextView.setText(currentPressure+"hPa");
pressureTextView.invalidate();
}
if (!Float.isNaN(currentLight)){
String lightStr="Sunny";
if (currentLight<=SensorManager.LIGHT_CLOUDY)
lightStr="night";
else if (currentLight<=SensorManager.LIGHT_OVERCAST)
lightStr="Cloudy";
else if (currentLight<=SensorManager.LIGHT_SUNLIGHT)
lightStr="Overcast";
lightTextView.setText(lightStr);
lightTextView.invalidate();
}
if (!Float.isNaN(currentTemperature)){
temperatureTextView.setText(currentTemperature+"C");
temperatureTextView.invalidate();
}
}
});
}
}
❹ android, 开发天气app需要哪些知识
安卓编程设计很多方面,非常复杂,需要系统的学习才可以,这里以一个简单的天气预报app编程为例:
public class WebServiceUtil
{
// 定义Web Service的命名空间
static final String SERVICE_NS = "http://WebXml.com.cn/";
// 定义Web Service提供服务的URL
static final String SERVICE_URL = "http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx";
public static List getProvinceList()
{
// 需要调用的方法名(获得本天气预报Web Services支持的洲、国内外省份和城市信息)
String methodName = "getRegionProvince";
// 创建HttpTransportSE传输对象
HttpTransportSE httpTranstation = new HttpTransportSE(SERVICE_URL);
httpTranstation.debug = true;
// 使用SOAP1.1协议创建Envelop对象
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
// 实例化SoapObject对象
SoapObject soapObject = new SoapObject(SERVICE_NS, methodName);
envelope.bodyOut = soapObject;
// 设置与.Net提供的Web Service保持较好的兼容性
envelope.dotNet = true;
try
{
// 调用Web Service
httpTranstation.call(SERVICE_NS + methodName, envelope);
if (envelope.getResponse() != null)
{
// 获取服务器响应返回的SOAP消息
SoapObject result = (SoapObject) envelope.bodyIn;
SoapObject detail = (SoapObject) result.getProperty(methodName
+ "Result");
// 解析服务器响应的SOAP消息。
return parseProvinceOrCity(detail);
}
} catch (Exception e)
{
e.printStackTrace();
}
return null;
}
public static List getCityListByProvince(String province)
{
// 需要调用的方法名(获得本天气预报Web Services支持的城市信息,根据省份查询城市集合:带参数)
String methodName = "getSupportCityString";
HttpTransportSE httpTranstation = new HttpTransportSE(SERVICE_URL);
httpTranstation.debug = true;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
SoapObject soapObject = new SoapObject(SERVICE_NS, methodName);
soapObject.addProperty("theRegionCode", province);
envelope.bodyOut = soapObject;
envelope.dotNet = true;
try
{
// 调用Web Service
httpTranstation.call(SERVICE_NS + methodName, envelope);
if (envelope.getResponse() != null)
{
// 获取服务器响应返回的SOAP消息
SoapObject result = (SoapObject) envelope.bodyIn;
SoapObject detail = (SoapObject) result.getProperty(methodName
+ "Result");
// 解析服务器响应的SOAP消息。
return parseProvinceOrCity(detail);
}
} catch (Exception e)
{
e.printStackTrace();
}
return null;
}
private static List parseProvinceOrCity(SoapObject detail)
{
ArrayList result = new ArrayList();
for (int i = 0; i < detail.getPropertyCount(); i++)
{
String str = detail.getProperty(i).toString();
// 解析出每个省份
result.add(str.split(",")[0]);
}
return result;
}
public static SoapObject getWeatherByCity(String cityName)
{
// 根据城市或地区名称查询获得未来三天内天气情况、现在的天气实况、天气和生活指数
String methodName = "getWeather";
HttpTransportSE httpTranstation = new HttpTransportSE(SERVICE_URL);
httpTranstation.debug = true;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
SoapObject soapObject = new SoapObject(SERVICE_NS, methodName);
soapObject.addProperty("theCityCode", cityName);
envelope.bodyOut = soapObject;
envelope.dotNet = true;
try
{
// 调用Web Service
httpTranstation.call(SERVICE_NS + methodName, envelope);
if (envelope.getResponse() != null)
{
// 获取服务器响应返回的SOAP消息
SoapObject result = (SoapObject) envelope.bodyIn;
SoapObject detail = (SoapObject) result.getProperty(methodName
+ "Result");
// 解析服务器响应的SOAP消息。
return detail;
}
} catch (Exception e)
{
e.printStackTrace();
}
return null;
}
}
❺ android 如何实现获取天气预报信息
方法步骤(以安卓5.0为例)
一、打开GPS
九、提示
1.适时刷新天气需要开启GPS定位。
2.在没有WIFI的地方刷新天气需要消耗一定的流量,刷新频率越高,消耗流量越多。
❻ android软件开发:中国气象局api接口(显示4、5天的天气),能实际有用的,日期也得正确
中国国家气象局天气预报接口总共提供了三个:
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
最详细的信息来自第三个接口。上面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":"不易发"}}[/code]
我们可以解析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恤等夏季服装。年老体弱者宜着长袖衬衫和单裤。",
<!--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如何获取天气预报主要使用了中国天气网的接口,使用webView显示。
工具/原料
Android Studio
方法/步骤
首先我们打开下载安装好的Android Studio然后新建一个项目,我这里为了方便就直接添加一个Activity了
然后我们添加界面布局代码,布局如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<Button
android:id="@+id/bj"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bj" />
<Button
android:id="@+id/sh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sh" />
<Button
android:id="@+id/heb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/heb" />
<Button
android:id="@+id/cc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cc" />
<Button
android:id="@+id/sy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sy" />
<Button
android:id="@+id/gz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/gz" />
</LinearLayout>
<WebView android:id="@+id/webView1"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:focusable="false"
android:layout_weight="1"
/>
</LinearLayout>
然后我们添加后台代码:
package com.basillee.asus.demo;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
public class MainActivity7 extends Activity implements OnClickListener {
private WebView webView; //声明WebView组件的对象
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity7);
webView=(WebView)findViewById(R.id.webView1); //获取WebView组件
webView.getSettings().setJavaScriptEnabled(true); //设置JavaScript可用
webView.setWebChromeClient(new WebChromeClient()); //处理JavaScript对话框
webView.setWebViewClient(new WebViewClient()); //处理各种通知和请求事件,如果不使用该句代码,将使用内置浏览器访问网页
webView.loadUrl("http://m.weather.com.cn/m/pn12/weather.htm "); //设置默认显示的天气预报信息
webView.setInitialScale(57*4); //放网页内容放大4倍
Button bj=(Button)findViewById(R.id.bj); //获取布局管理器中添加的“北京”按钮
bj.setOnClickListener(this);
Button sh=(Button)findViewById(R.id.sh); //获取布局管理器中添加的“上海”按钮
sh.setOnClickListener(this);
Button heb=(Button)findViewById(R.id.heb); //获取布局管理器中添加的“哈尔滨”按钮
heb.setOnClickListener(this);
Button cc=(Button)findViewById(R.id.cc); //获取布局管理器中添加的“长春”按钮
cc.setOnClickListener(this);
Button sy=(Button)findViewById(R.id.sy); //获取布局管理器中添加的“沈阳”按钮
sy.setOnClickListener(this);
Button gz=(Button)findViewById(R.id.gz); //获取布局管理器中添加的“广州”按钮
gz.setOnClickListener(this);
}
@Override
public void onClick(View view){
switch(view.getId()){
case R.id.bj: //单击的是“北京”按钮
openUrl("101010100T");
break;
case R.id.sh: //单击的是“上海”按钮
openUrl("101020100T");
break;
case R.id.heb: //单击的是“哈尔滨”按钮
openUrl("101050101T");
break;
case R.id.cc: //单击的是“长春”按钮
openUrl("101060101T");
break;
case R.id.sy: //单击的是“沈阳”按钮
openUrl("101070101T");
break;
case R.id.gz: //单击的是“广州”按钮
openUrl("101280101T");
break;
}
}
//打开网页的方法
private void openUrl(String id){
webView.loadUrl("http://m.weather.com.cn/m/pn12/weather.htm?id="+id+" "); //获取并显示天气预报信息
}
}
然后我们点击Android Studio上面的运行按钮:
这里要访问网络我们要添加权限:
<uses-permission android:name="android.permission.INTERNET" />
6
我们然后可以在模拟器上面可以看到获取的天气情况
❽ android 做一个天气预报的步骤
这些问题还是建议你去其他专业的平台去问,那些csdn有很多大神在,他们会详细专业一点的回答道你,我的水平也就只是做过课程设计的而已,一般的步骤大概是规划好基础模型(就是要做出的基本功能)--做好框架控件那些(软件的话,我当时是用AS来做的)--然后就实现页面的跳转连接--最后就关联后台数据(这个可以说核心了,毕竟天气预报就是需要数据,实时更新的那种)
❾ android,开发一款简单的天气app,android的四大组件会用到哪几个如果是功能较多的天气app呢
哪些是4大组件,,,,,,,,,重点是资料的来源。显示无非是界面,那要看需求了,如单界面、是否透明、是否桌面。。。。。。。。。。。。。