开发者

URI Scheme definition?

开发者 https://www.devze.com 2023-02-22 03:05 出处:网络
I\'m working off this tutorial: http://www.developer.com/ws/article.php/10927_3833306_2/Creating-a-Home-Screen-App-Widget-on-Android.htm

I'm working off this tutorial: http://www.developer.com/ws/article.php/10927_3833306_2/Creating-a-Home-Screen-App-Widget-on-Android.htm

It includes the following code:

   widgetUpdate.setData(
   Uri.withAppendedPath(Uri.parse(
   ImagesWidgetProvider.URI_SCHE开发者_StackOverflow社区ME + "://widget/id/"), 
   String.valueOf(appWidgetId)));

My question is, what should URI_SCHEME be defined as and where?


You define value of uri scheme as some UNIQUE string for your application.

It MUST have to be defined in your menifest file: Example here

   <receiver
        android:name="ImagesWidgetProvider">
        <intent-filter>
            <action
                android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                <data android:scheme="my_widget_scheme" />
        </intent-filter>
        <meta-data
            android:name="android.appwidget.provider"
            android:resource="@xml/imageswidget_info" />
    </receiver>

Then, for convenience, you may put that value in some variable (even better if static final) of your code: Check here

public static final String URI_SCHEME = "my_widget_scheme";

Note that, UNIQUE scheme string definition in manifest xml is compulsory. The definition in class member variable is not compulsory. but, it is a very very very good practice.


According to http://code.google.com/p/android-widget-development-tutorials/source/browse/trunk/src/com/mamlambo/imageswidget/ImagesWidgetProvider.java?r=2#18 it should be "image_widget".

0

精彩评论

暂无评论...
验证码 换一张
取 消