當前位置:首頁 » 安卓系統 » android天氣開發

android天氣開發

發布時間: 2022-09-14 19:17:47

❶ 基於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開發天氣預報代碼運行的時候老是報錯,圖片如下:

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大組件,,,,,,,,,重點是資料的來源。顯示無非是界面,那要看需求了,如單界面、是否透明、是否桌面。。。。。。。。。。。。。

熱點內容
原力文件夾 發布:2025-01-09 05:51:44 瀏覽:125
php寫入文本 發布:2025-01-09 05:45:00 瀏覽:877
考研編程作品 發布:2025-01-09 05:35:00 瀏覽:332
安卓相冊哪個好看 發布:2025-01-09 05:16:01 瀏覽:982
java分析數據 發布:2025-01-09 05:16:00 瀏覽:853
視頻md5加密 發布:2025-01-09 05:08:59 瀏覽:926
xp系統文件夾加密 發布:2025-01-09 04:52:38 瀏覽:171
外部調用shell腳本內函數 發布:2025-01-09 04:49:14 瀏覽:256
java資料庫搜索 發布:2025-01-09 04:48:30 瀏覽:621
pythoninspect 發布:2025-01-09 04:42:12 瀏覽:413