Roger
Roger

Reputation: 4269

URI Scheme definition?

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_SCHEME + "://widget/id/"), 
   String.valueOf(appWidgetId)));

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

Upvotes: 0

Views: 413

Answers (2)

Sarwar Erfan
Sarwar Erfan

Reputation: 18058

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.

Upvotes: 1

Related Questions