android天气预报app源码(安卓简单天气预报app源码)

今天给各位分享android天气预报app源码的知识,其中也会对安卓简单天气预报app源码进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

安卓天气预报源码,从网络获取获取信息那种的,求大神教教我

你要求太多了,除非是干这行的且有相关项目。即使如此也不会轻易给你。既然你是答辩,那么可以给你大概说下都是什么东西。关键就是一个后台service,设置成24小时一次访问网络,获取数据,至于天气预报信息,是从服务器请求下来的数据。其他的就是把这些数据适配到界面的问题了。‘ 建议你去百度上搜下: 1,Activity组件 2,service组件 3,webService 4,Adapter 当让,以上都是安卓相关。 既然是毕业设计,就花点时间看下吧。记得当时我也选个自己不怎么会的项目,然后钻了一段时间,最后毕业答辩虽然说的不好,可是都是自己的东西,老师们也知道大学情况,看到有人能自己努力不去抄袭,也很感动的给了好评。我谢谢那些令人尊敬的老师给我的鼓励。加油吧... ...

怎样获取当前的城市,并获得天气 android源码

名称:265天气根据IP自动获得当地的天气情况 代码:iframe src="weather/weather/Weather/news_new/inc/ss258/cgi-bin/news_weather_search?city=厦门" allowTransparency="true"/iframe 说明 :这种适合于在网页的正栏插入。上面的城市可以自定,比如厦门可改成别的。定制的方法是修改我代码中标红的 名称。这里比较简单,直接用汉字改就行了。比如是福州的,你就直接把“厦门”改成福州就行。名称:QQ天气预报代码(四) 代码 :iframe width=160 height=230 frameborder=0 scrolling=NO src=appnews/cgi-bin/news_qq_search?city=南昌/iframe 名称:QQ天气预报代码(五) 代码 :iframe src="appnews/cgi-bin/news_qq_search?city=南昌" frameborder="0" width="160" scrolling="no" height="230"/iframe

求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.scheduleAtFixedRate(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编程为例:

public class WebServiceUtil

{

// 定义Web Service的命名空间

static final String SERVICE_NS = "";

// 定义Web Service提供服务的URL

static final String SERVICE_URL = "";

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天气预报app源码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于安卓简单天气预报app源码、android天气预报app源码的信息别忘了在本站进行查找喔。

1、本网站名称:源码村资源网
2、本站永久网址:https://www.yuanmacun.com
3、本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
4、本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
5、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
6、本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新。
源码村资源网 » android天气预报app源码(安卓简单天气预报app源码)
您需要 登录账户 后才能发表评论

发表评论

欢迎 访客 发表评论