android天氣源代碼
❶ android項目源碼下載
對於讀項目源代碼來說,可能對大多數人是件困難的事。首先,第一個障礙:看到項目,就已經放棄! 如果有十個人,可能有5個人以上會是上面這種情況,分析其想法:這么多的代碼,我要怎麼讀啊!我要讀好久啊!算了,還是看小Demo吧,所以這樣,他們也就只是把這個項目導入到eclipse中,點了幾下滑鼠,然後就沒有下文了。 解決辦法:其實他們終止的原因很簡單,就是嫌麻煩,那好吧,告訴你,這點麻煩都能對你造成影響,其實你的開發之路也可以終止了。任何東西,你要學到它,你就必須花時間、花精力、還要有面對困難的准備。想一步登天,有可能,除非你是天才,但畢竟天才太少了!對於開發,不是學習1+1,所以,先擺正心態吧,那要具備怎樣的心態呢?那就是:有面對困難的准備,也有解決苦難的信心。 心態問題解決了,那就是讀代碼的技巧了,很多人拿到一個項目不知道怎麼入手,乾脆就胡亂的一通看,看到一定時候發現,實在進行不下去了,又開始重新梳理自己的思路。這樣是很浪費時間的,其實對於讀一個項目,最好按照以下步驟進行(
個人意見,僅供參考
): 1、使用這個應用或者游戲,直到熟悉它的使用流程和功能 2、根據自己的體驗分析代碼實現(整體) 3、如果有條件和原作者請教項目思路 4、從最先啟動的Activity開始,弄懂每個Activity功能如何實現以及它的布局實現 5、遇到不懂的代碼,首先找搜索引擎(一般都能解決)。還不行就可以請教他人了 6、對新學到的知識點,一定要總結下來,並且定期的去回顧
7、最重要的一點:
我認為要自己動手寫,那怕是重新寫一遍這個項目,或者自己設計一個類似的,再或者只寫這個項目中的一部分。 為什麼要自己動手呢?大家都知道coder這個東西,那怕你理論學得再好,不動手,那也是毫無意義的!所以,動手寫一下,你會遇到問題,你就會解決問題,這樣,你才能學到更多。這就是經驗·······
以上回答你滿意么?
❷ 基於android的天氣預報系統
用你手機自帶的「應用商店」,搜索天氣,出來的都是適配你手機系統的天氣預報app。
當然,你的手機是安卓的,那就是適配安卓系統的了。
❸ android 代碼可以獲取天氣的氣壓嗎
可以,前提是設備要有氣壓計硬體
獲取氣壓的代碼:
java">SensorManagersm=(SensorManager)getSystemService(Context.SENSOR_SERVICE);//獲取系統感測器服務
sm.getDefaultSensor(Sensor.TYPE_PRESSURE);//獲取氣壓計對象
//注冊氣壓計監聽器
sm.registerListener(newSensorEventListener(){
@Override
publicvoidonSensorChanged(SensorEventevent){
//TODOAuto-generatedmethodstub
float[]value=event.values;
for(inti=0;i<value.length;i++){
Log.i("Barometer",float[i]);
}
}
@Override
publicvoidonAccuracyChanged(Sensorsensor,intaccuracy){
//TODOAuto-generatedmethodstub
}
},baroSensor,SensorManager.SENSOR_DELAY_NORMAL);
❹ 如何自己動手做一個android天氣預報的app
一個Android天氣預報要用到的代碼文件,可顯示操作菜單,顯示未來四天天氣、將全國城市列表寫入資料庫、初始化數據解析類,界面控制項,消息接收器Handler、線程消息接收器、左側菜單選擇事件監聽、後退按鈕監聽等,代碼為:
227
if(mycitys.size()==1){
228
showToast("至少要保留一個城市");
229
}else{
230
mycitys.remove(position);
231
writeMyCitys();
232
sAdapter.notifyDataSetChanged();
233
currCityId=mycitys.get(0).get("cityId");
234
changeSearchState();
235
}
236
}
237
});
238
builder.setNegativeButton("取 消",
239
new DialogInterface.OnClickListener() {
240
public void onClick(DialogInterface dialog, int which) {
241
dialog.dismiss();
242
}
243
});
244
builder.show();
245
return false;
246
}
247
//
監聽後退按鈕
248
@Override
249
public boolean
onKeyDown(int
keyCode, KeyEvent event) {
250
if (keyCode ==
KeyEvent.KEYCODE_BACK) {
251
// 如果當前menu沒有顯示
252
if (!isBack) {
253
showToast("再按一次退出");
254
downTime = event.getDownTime();
255
isBack = true;
256
return true;
257
} else {
258
if (event.getDownTime() -
downTime <= 2000) {
259
AppManager.getAppManager().AppExit(Weather.this);
260
} else {
261
showToast("再按一次退出");
262
downTime = event.getDownTime();
263
return true;
264
}
265
}
266
}
267
return super.onKeyDown(keyCode, event);
268
}
269
@Override
270
protected void
onDestroy() {
271
if(mVibrator!=null){
272
mVibrator.cancel();
273
}
274
super.onDestroy();
275
}
276
}
❺ 我剛開始學android開發,現在想在一個activity添加進天氣預報功能。我希望它作用主要就是顯示當前的天氣
你的要求太高了吧
要得到當前的位置的掉GPS 定位 或者 你上網登錄了以後根據IP知道地址
天氣預報到不難WebService 會寫就能調用
你要是要做出來炫耀,就先把分拿出來 200分是最起碼的
財富等回答後再給,20-50不等------騙誰呢,就我無聊還鳥你
❻ android怎樣使用天氣預報介面 實現天氣預報
使用搜索引擎可以得到很多的天氣預報介面,這里以某個api為例
http://wthrcdn.etouch.cn/WeatherApi
參數為city=城市名稱
嘗試獲取南昌的天氣預報
http://wthrcdn.etouch.cn/WeatherApi?city=南昌
得到下面xml數據
<?xmlversion="1.0"encoding="utf-8"?>
<resp>
<city>南昌</city>
<updatetime>16:55</updatetime>
<wen>5</wen>
<fengli>3級</fengli>
<shi>90%</shi>
<fengxiang>北風</fengxiang>
<sunrise_1>06:54</sunrise_1>
<sunset_1>17:19</sunset_1>
<sunrise_2/>
<sunset_2/>
<environment>
<aqi>26</aqi>
<pm25>13</pm25>
<suggest>各類人群可自由活動</suggest>
<quality>優</quality>
<MajorPollutants/>
<o3>44</o3>
<co>1</co>
<pm10>14</pm10>
<so2>4</so2>
<no2>27</no2>
<time>16:00:00</time>
</environment>
<yesterday>
<date_1>4日星期五</date_1>
<high_1>高溫11℃</high_1>
<low_1>低溫7℃</low_1>
<day_1>
<type_1>陰</type_1>
<fx_1>無持續風向</fx_1>
<fl_1>微風</fl_1>
</day_1>
<night_1>
<type_1>小到中雨</type_1>
<fx_1>北風</fx_1>
<fl_1>3-4級</fl_1>
</night_1>
</yesterday>
<forecast>
<weather>
<date>5日星期六</date>
<high>高溫7℃</high>
<low>低溫5℃</low>
<day>
<type>中到大雨</type>
<fengxiang>無持續風向</fengxiang>
<fengli>微風級</fengli>
</day>
<night>
<type>小到中雨</type>
<fengxiang>無持續風向</fengxiang>
<fengli>微風級</fengli>
</night>
</weather>
<weather>
<date>6日星期天</date>
<high>高溫10℃</high>
<low>低溫5℃</low>
<day>
<type>陰</type>
<fengxiang>無持續風向</fengxiang>
<fengli>微風級</fengli>
</day>
<night>
<type>多雲</type>
<fengxiang>無持續風向</fengxiang>
<fengli>微風級</fengli>
</night>
</weather>
<weather>
<date>7日星期一</date>
<high>高溫13℃</high>
<low>低溫6℃</low>
<day>
<type>多雲</type>
<fengxiang>無持續風向</fengxiang>
<fengli>微風級</fengli>
</day>
<night>
<type>晴</type>
<fengxiang>無持續風向</fengxiang>
<fengli>微風級</fengli>
</night>
</weather>
<weather>
<date>8日星期二</date>
<high>高溫13℃</high>
<low>低溫7℃</low>
<day>
<type>晴</type>
<fengxiang>無持續風向</fengxiang>
<fengli>微風級</fengli>
</day>
<night>
<type>多雲</type>
<fengxiang>無持續風向</fengxiang>
<fengli>微風級</fengli>
</night>
</weather>
<weather>
<date>9日星期三</date>
<high>高溫13℃</high>
<low>低溫10℃</low>
<day>
<type>小雨</type>
<fengxiang>無持續風向</fengxiang>
<fengli>微風級</fengli>
</day>
<night>
<type>小雨</type>
<fengxiang>無持續風向</fengxiang>
<fengli>微風級</fengli>
</night>
</weather>
</forecast>
<shus>
<shu>
<name>晨練指數</name>
<value>不宜</value>
<detail>有較強降水,請避免戶外晨練,建議在室內做適當鍛煉,保持身體健康。</detail>
</shu>
<shu>
<name>舒適度</name>
<value>較舒適</value>
<detail>白天有雨,人們會感到有些涼意,但大部分人完全可以接受。</detail>
</shu>
<shu>
<name>穿衣指數</name>
<value>較冷</value>
<detail>建議著厚外套加毛衣等服裝。年老體弱者宜著大衣、呢外套加羊毛衫。</detail>
</shu>
<shu>
<name>感冒指數</name>
<value>極易發</value>
<detail>將有一次強降溫過程,天氣寒冷,且空氣濕度較大,極易發生感冒,請特別注意增加衣服保暖防寒。</detail>
</shu>
<shu>
<name>晾曬指數</name>
<value>不宜</value>
<detail>有較強降水,不適宜晾曬。若需要晾曬,請在室內准備出充足的空間。</detail>
</shu>
<shu>
<name>旅遊指數</name>
<value>較不宜</value>
<detail>天氣稍涼,有微風,同時有有較強降水,會給出行產生很多麻煩,建議好還是多選擇在室內活動!。</detail>
</shu>
<shu>
<name>紫外線強度</name>
<value>最弱</value>
<detail>屬弱紫外線輻射天氣,無需特別防護。若長期在戶外,建議塗擦SPF在8-12之間的防曬護膚品。</detail>
</shu>
<shu>
<name>洗車指數</name>
<value>不宜</value>
<detail>不宜洗車,未來24小時內有雨,如果在此期間洗車,雨水和路上的泥水可能會再次弄臟您的愛車。</detail>
</shu>
<shu>
<name>運動指數</name>
<value>較不宜</value>
<detail>有較強降水,建議您選擇在室內進行健身休閑運動。</detail>
</shu>
<shu>
<name>約會指數</name>
<value>不適宜</value>
<detail>較強降水天氣會給室外約會增添許多麻煩,盡量不要外出約會,最好在室內促膝談心。</detail>
</shu>
<shu>
<name>雨傘指數</name>
<value>帶傘</value>
<detail>有較強降水,您在外出的時候一定要帶雨傘,以免被雨水淋濕。</detail>
</shu>
</shus>
</resp>
得到數據後使用XML解析數據即可,最好是建立一個實體類來存儲數據
下面是使用DOM方式解析部分數據代碼
DocumentBuilderbuilder=DocumentBuilderFactory.newInstance().newDocumentBuilder();
//is是網路連接得到的輸入流
Documentdoc=builder.parse(is);
if(doc==null)thrownewException();
Elementelement=doc.getDocumentElement();
NodeListchildList=element.getChildNodes();
for(inti=0;i<childList.getLength();i++){
Elemente=(Element)childList.item(i);
Stringtag=e.getTagName();
Stringtext=e.getTextContent();
if("city".equals(tag)){
//城市
}elseif("updatetime".equals(tag)){
//更新時間
}elseif("wen".equals(tag)){
//即時溫度
}elseif("fengli".equals(tag)){
//風力
}elseif("shi".equals(tag)){
//濕度
}elseif("fengxiang".equals(tag)){
//風向
}
}
❼ 求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怎麼獲取實時天氣
准備工作:
1.下載華為能力SDK;http://imax.vmall.com/nj-campus/universityEpDown/toDownPage
2.申請一個應用獲取appId和appkey,待會要用到。
簡單的思路就是先通過網路或者gps獲取到當前位置的經緯度,然後通過sdk查詢溫度,獲取結果。
具體步驟如下:
1.創建工程
把sdk中jar包拖到工程中的libs文件夾下面。
2.主類代碼如下
package com.empty.weatherreport;
import com.empty.weatherreport.WeatherUtil.SCell;
import com.empty.weatherreport.WeatherUtil.SItude;
import com.imax.vmall.sdk.android.common.adapter.ServiceCallback;
import com.imax.vmall.sdk.android.entry.CapabilityService;
import com.imax.vmall.sdk.android.entry.CommonService;
import com.imax.vmall.sdk.android.huawei.weather.WeatherService;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
public class WeatherActivity extends Activity {
private MyHandler myHandler;
private ProgressDialog mProgressDialog;
private Location mLocation;
private boolean sdkStatus;
//Tool to get weather
/**
* CommonService
*/
private CommonService cs;
/**
* WeatherService
*/
private WeatherService weather;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_weather);
sdkStatus=false;
myHandler=new MyHandler();
//初始化業務介面實例
weather = CapabilityService.getWeatherServiceInstance();
//實例化CommonService
cs=CommonService.getInstance();
initSDK();
}
private void initSDK()
{
//應用ID,請去iMAX平台注冊申請
String appId="******";
//應用Key
String appKey="******";
//通過CommonService調用鑒權介面,在調用其它能力前必須保證鑒權初始化成功
cs.init(WeatherActivity.this,appId, appKey, new ServiceCallback() {
public void onError(String arg0) {
// TODO Auto-generated method stub
//設置消息
Message msg = new Message();
msg = new Message();
msg.what = 2;
msg.obj = "SDK initialize failed!";
myHandler.sendMessage(msg);
}
public void onComplete(String arg0) {
// TODO Auto-generated method stub
//設置消息
Message msg = new Message();
msg = new Message();
msg.what = 2;
msg.obj = "SDK initialize success!";
sdkStatus=true;
myHandler.sendMessage(msg);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_weather, menu);
return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
// TODO Auto-generated method stub
if(item.getItemId()==R.id.menu_settings) Toast.makeText(getApplicationContext(), "Ha", Toast.LENGTH_SHORT).show();
if(item.getItemId()==R.id.menu_weather)
{
if(sdkStatus)
{
/** 彈出一個等待狀態的框 */
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage("Waiting...");
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mProgressDialog.show();
WeatherThread m = new WeatherThread();
new Thread(m).start();
}
else
Toast.makeText(getApplicationContext(), "SDK not installed", Toast.LENGTH_SHORT).show();
}
return super.onMenuItemSelected(featureId, item);
}
/** 顯示結果 */
private void showResult(String s) {
String tmp[]=s.split("\"");
for(int i=0;i<tmp.length;i++)
Log.i("tmp"+i, tmp[i]);
new AlertDialog.Builder(this) .setTitle("Weather") .setMessage("latitude:"+mLocation.getLatitude()+"\n longitude:"
+mLocation.getLongitude()+"\ntmperature:"+tmp[21]) .show();
}
class MyHandler extends Handler {
public MyHandler() {
}
public MyHandler(Looper L) {
super(L);
}
// 子類必須重寫此方法,接管數據
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
Log.d("MyHandler", "handleMessage......");
/** 顯示結果 */
switch(msg.what)
{
case 1:
Log.i("Error", "case1");
mProgressDialog.dismiss();
showResult((String)msg.obj);
break;
case 2:
Toast.makeText(getApplicationContext(), (String)msg.obj, Toast.LENGTH_SHORT).show();
break;
default:;
}
super.handleMessage(msg);
// 此處可以更新UI
}
}
class WeatherThread implements Runnable {
public void run() {
final Message msg = new Message();
msg.what=1;
try {
mLocation=getLocation(WeatherActivity.this);
weather.getWeather(Double.toString(mLocation.getLongitude()),Double.toString(mLocation.getLatitude()), new ServiceCallback()
{
public void onError(String arg0)
{
//api介面調用錯誤響應
Log.i("Error", "getWeather error:"+arg0);
//設置消息
msg.obj = arg0;
/** 關閉對話框 */
myHandler.sendMessage(msg); // 向Handler發送消息,更新UI
}
public void onComplete(String arg0)
{
//api介面調用成功響應
Log.i("Complete", "getWeather complete:"+arg0);
//設置消息
msg.obj = arg0;
/** 關閉對話框 */
myHandler.sendMessage(msg); // 向Handler發送消息,更新UI
}
});
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//Get the Location by GPS or WIFI
public Location getLocation(Context context) {
LocationManager locMan = (LocationManager) context
.getSystemService(Context.LOCATION_SERVICE);
Location location = locMan
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location == null) {
location = locMan
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
return location;
}
}
3.載manifest文件中添加許可權
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" >
</uses-permission>
<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" >
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
❾ 求安卓天氣軟體源代碼!有載入界面、天氣顯示頁面、未來幾天天氣界面、切換城市界面四個界面的
你要求太多了,除非是干這行的且有相關項目。即使如此也不會輕易給你。既然你是答辯,那麼可以給你大概說下都是什麼東西。關鍵就是一個後台service,設置成24小時一次訪問網路,獲取數據,至於天氣預報信息,是從伺服器請求下來的數據。其他的就是把這些數據適配到界面的問題了。『
建議你去網路上搜下:
1,Activity組件
2,service組件
3,webService
4,Adapter
當讓,以上都是安卓相關。
既然是畢業設計,就花點時間看下吧。記得當時我也選個自己不怎麼會的項目,然後鑽了一段時間,最後畢業答辯雖然說的不好,可是都是自己的東西,老師們也知道大學情況,看到有人能自己努力不去抄襲,也很感動的給了好評。我謝謝那些令人尊敬的老師給我的鼓勵。加油吧... ...