I have a RemoteViews instance, received from another app as parcelable data. I cannot simply change the service result (still have to provide backwards compatibility).
The received RemoteViews has a simple layout: a LinearLayout container, with a TextView and an ImageView inside. The image view comes with a Bitmap image set.
Up to now, that remote view was inflated by calling remoteView.apply(Context context, ViewGroup parent)
, and then the resulting view is added to another layout on the screen.
After updating the support library to the latest version at the moment: in my case from 25.3.1 to 26.1.0, calling remoteView.apply(Context, ViewGroup)
started throwing an exception:
android.widget.RemoteViews$ActionException: view: android.support.v7.widget.AppCompatImageView can't use method with RemoteViews: setImageBitmap(class android.graphics.Bitmap)
It seems to be caused by missing RemotableViewMethod
annotation on the setImageBitmap()
of the AppCompatImageView. Maybe it was removed in support 26+ or never existed, as AppCompatImageView is not intended for use in RemoteViews...
It seems that in previous releases of the support library (23.1.0), "setImageResource(int)" and "setBackgroundResource(int)" started failing the same way: https://issuetracker.google.com/issues/37071559
What I'm trying to understand is:
- Does it work as intended? I suppose Yes, but then:
- How to workaround that? (probably I'm missing something...) Or:
- Is there a way to avoid inflating AppCompatimageViews instead of simple ImageView, when using
RemoteViews.apply(Context, ViewGroup)
for inflation of RemoteViews? The context that is supplied to theapply
method is "AppCompatActivity".
The only "solution" (an ugly workaround), I was able to find, is to retrieve the Bitmap data from the RemoteView using reflection, and then use that image in my own layout. (Instead of inflating the RemoteViews and adding everything to the layout).
Thanks in advance