现在的位置: 首页 > 综合 > 正文

weatherWallpaper

2014年03月24日 ⁄ 综合 ⁄ 共 3610字 ⁄ 字号 评论关闭

今天终于抽出时间,写了下weahterwallpaper的GeoLocation模块。之前上网搜了下,发现这个Ideal已经不是first,但事已至此,也没什么好说的了。

有几个bug记录一下。

NETWORK据反映在异步回调函数onLocationChange里一直获得null。我连trigger不行,后改用GPS.

真机不懂为什么有不能和电脑相连了。

操作: 编辑AndroidManifest.xml  增加调试参数android:debuggable="true", 如下:
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">


google weather api

http://www.google.com/ig/api?hl=zh-cn&weather=,,,63107204,21651467

63.107204,21.651467

 android.permission.SET_WALLPAPER  为了切换壁纸

 <uses-permission android:name="android.permission.SET_WALLPAPER"/>

,必须在Manifest.xml中写明这个权限。

同时建立Service,必须声明<Service android:name="fooService"/>


之前百思不得其解,为什么真机调试自打系统还原后,就没能再成功识别到设备。今晚突然想到,估计是驱动没有装。当然这种繁琐的工作可以交个豌豆夹去解决。安装过豌豆夹之后,ADB有可以重新识别到我的小华了。


关于后台定时发起请求,更换壁纸,我的思路开始时选择Service ,比较不可能一个Activity 常开的,那还怎么看Wallpaper.但Service 启动后,如何定时刷新呢?刚开始想到用定时器,但看到网络上说用Handler,就去试用了下,但不懂为什么,在Service的onStart里post一个runable(在Run中Postdelay(r)),必须start两次才行,怀疑线程队列被service给占用了。

后来想到了宋兄的Android4.0壁纸切换那个软件,他使用的是AlarmService

 PendingIntent pi = PendingIntent.getBroadcast(AlarmActivity.this, 0, intent, 0);  

AlarmManager am = (AlarmManager) getSystemService(Activity.ALARM_SERVICE);  
                        am.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), pi);//设置闹钟  
                        am.setRepeating(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), (10*1000), pi);//重复设置  

写一个广播接收,每隔N重复启动Service.


-------------------------about sharedpreferences----------------------------------

SharedPreferences是以键值对来存储应用程序的配置信息的一种方式,它只能存储基本数据类型。一个程序的配置文件仅可以在本应用程序中使用,或者说只能在同一个包内使用,不能在不同的包之间使用。
实际上SharedPreferences是采用了XML格式将数据存储到设备中,在DDMS中的File Explorer中的/data/data/<package name>/shares_prefs下。

SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);

setting.edit().putBoolean(“silentMode”,mSilentMode).commit();


* 文件存放路径: 因为我的这个例子的pack_name 为:package com.android.SharedPreferences;

  所以存放路径为:data/data/com.android.SharedPreferences/share_prefs/contacts.xml


Toast.makeText(SharedPreferencesActivity.this, "success",Toast.LENGTH_LONG).show();

----------------------------------------------------------------------------------------------

关于google weather api,官方并不能保证稳定性,毕竟不是公开的,但我想无私的Google是不会介意的,大不了到时候在切换到yahoo!去,不过Yahoo!人老珠黄,也说不准。

由于没有官方的文档,the enumeration of the weather condition is a big problem,但幸运的是,还是被我找到了这个,从source可以推出个大概。

Level 1
8/18/10

http://www.google.ru/ig/images/weather/sunny.gif

http://www.google.ru/ig/images/weather/mostly_sunny.gif

http://www.google.ru/ig/images/weather/partly_cloudy.gif

http://www.google.ru/ig/images/weather/mostly_cloudy.gif

http://www.google.ru/ig/images/weather/chance_of_storm.gif

http://www.google.ru/ig/images/weather/rain.gif

http://www.google.ru/ig/images/weather/chance_of_rain.gif

http://www.google.ru/ig/images/weather/chance_of_snow.gif

http://www.google.ru/ig/images/weather/cloudy.gif

http://www.google.ru/ig/images/weather/mist.gif

http://www.google.ru/ig/images/weather/storm.gif

http://www.google.ru/ig/images/weather/thunderstorm.gif

http://www.google.ru/ig/images/weather/chance_of_tstorm.gif

http://www.google.ru/ig/images/weather/sleet.gif

http://www.google.ru/ig/images/weather/snow.gif

http://www.google.ru/ig/images/weather/icy.gif

http://www.google.ru/ig/images/weather/dust.gif

http://www.google.ru/ig/images/weather/fog.gif

http://www.google.ru/ig/images/weather/smoke.gif

http://www.google.ru/ig/images/weather/haze.gif

http://www.google.ru/ig/images/weather/flurries.gif

11.15

考虑到有可能定位失败。所以提供用户输入来修正:

  http://www.google.com/ig/api?weather=Beijing 

项目有时候不要开太多,容易写错到别的项目里面,今天往一个string.xml写值,但r.java怎么都出不来,原来写错项目了。

在string里写键值对有时候会突然报错,没纠察原因,估计是我的英文语法错了?哈哈,开个玩笑


听到刘同学说App不能取消更换壁纸,甚是惊讶,在测试的时候木有出现这个问题。仔细想了下,发现时启动的闹钟无法取消。

通过写入配置文件,多次启动bootService,这样做虽然是有一点牺牲了性能,但是最直接的办法...貌似用过bind启动可以获得service,但不管了。很累了

抱歉!评论已关闭.