How to create a backward compatible Android swap application widget?

I'm having trouble finding any tutorials on how to create a page widget widget, for example on Facebook, Twitter and FriendCaster.

I could use the new Android 3.0 + tools with an adapter, however it would be difficult to verify, since I have no devices, and my computer is not either.

+4
source share
2 answers

This can be done by providing your appwidget with a state that determines the page displayed on it. And assign the broadcast to the buttons to change the state.

  • Send a broadcast when the PendingIntent buttons are pressed .
  • receiver listen to the broadcast and track the status (page)
  • Update the application depending on the current state

Here is an example of incomplete code:

RemoteViews remoteViews = new RemoteViews(mContext.getPackageName(), R.layout.widget_weather); // update appwidget remoteviews depending on state (ie which page to show) remoteViews = populateViews(remoteViews, mState); // set next button Intent intent = new Intent(MYBROADCAST_NEXT); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, requestCode, intent, flags); remoteViews.setOnClickPendingIntent(R.id.appwidget_btn_next, pendingIntent); // set prev button intent = new Intent(MYBROADCAST_PREV); pendingIntent = PendingIntent.getBroadcast(context, requestCode, intent, flags); remoteView.setOnClickPendingIntent(R.id.appwidget_btn_prev, pendingIntent); // update the AppWidget ... 

Hope this helps you achieve what you want.

+3
source

You can use the compatibility package, it is compatible with feedback. The minimum API level is 4, this is Android 1.6

http://developer.android.com/sdk/compatibility-library.html

Use ViewPager, there are many examples. http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html

+1
source

Source: https://habr.com/ru/post/1379218/


All Articles