WEB开发网
开发学院手机开发Android 开发 Android 3.0自带的天气预报例子代码 阅读

Android 3.0自带的天气预报例子代码

 2011-03-19 11:57:21 来源:本站整理   
核心提示:Android 3.0正式版API Level 11中加入了一个天气预报例子,下面是manifest.xml中的关键代码,Android 3.0自带的天气预报例子代码,只是少了xml的编码头: <manifest xmlns:android="http://schemas.android.com/ap

Android 3.0正式版API Level 11中加入了一个天气预报例子,下面是manifest.xml中的关键代码,只是少了xml的编码头:

  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.android.weatherlistwidget">
   <uses-sdk android:minSdkVersion="11" />
   <application android:label="Weather Widget Sample">
     <receiver android:name="WeatherWidgetProvider">
       <intent-filter>
         <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
       </intent-filter>
           <meta-data android:name="android.appwidget.provider"
           android:resource="@xml/widgetinfo" />
     </receiver>

   <service android:name="WeatherWidgetService"
       android:permission="android.permission.BIND_REMOTEVIEWS"
       android:exported="false" />

   <provider android:name="WeatherDataProvider"
        android:authorities="com.example.android.weatherlistwidget.provider" />
   </application>
</manifest>

 这里WeatherDataProvider.java的源码为主要是ContentProvider相关的处理,这里作为appWidget的receiver

  class WeatherDataPoint {
   String city; //城市
   int degrees; //度数

   WeatherDataPoint(String c, int d) {
     city = c;
     degrees = d;
   }
}

 public class WeatherDataProvider extends ContentProvider {
   public static final Uri CONTENT_URI =
     Uri.parse("content://com.example.android.weatherlistwidget.provider");
   public static class Columns {
     public static final String ID = "_id";
     public static final String CITY = "city";
     public static final String TEMPERATURE = "temperature";
   }

private static final ArrayList<WeatherDataPoint> sData = new ArrayList<WeatherDataPoint>();

   @Override
   public boolean onCreate() {
     sData.add(new WeatherDataPoint("San Francisco", 13));
     sData.add(new WeatherDataPoint("New York", 1));
     sData.add(new WeatherDataPoint("Seattle", 7));
     sData.add(new WeatherDataPoint("Boston", 4));
     sData.add(new WeatherDataPoint("Miami", 22));
     sData.add(new WeatherDataPoint("Toronto", -10));
     sData.add(new WeatherDataPoint("Calgary", -13));
     sData.add(new WeatherDataPoint("Tokyo", 8));
     sData.add(new WeatherDataPoint("Kyoto", 11));
     sData.add(new WeatherDataPoint("London", -1));
     sData.add(new WeatherDataPoint("Nomanisan", 27));
     return true;
   }

   @Override
   public synchronized Cursor query(Uri uri, String[] projection, String selection,
       String[] selectionArgs, String sortOrder) {

1 2 3 4 5  下一页

Tags:Android 自带 天气预报

编辑录入:coldstar [复制链接] [打 印]
赞助商链接