I am working on widgets and i need to use this views.setImageViewResource method in AppWidgetProvider but this method wants integer but i have uri how can i solve this problem?
class AppWidgetBroadcast : AppWidgetProvider() {
private lateinit var database: DatabaseReference
private lateinit var mydatabase: FirebaseDatabase
override fun onUpdate(
context: Context,
appWidgetManager: AppWidgetManager,
appWidgetIds: IntArray
) {
// Perform this loop procedure for each widget that belongs to this
// provider.
appWidgetIds.forEach { appWidgetId ->
// Create an Intent to launch ExampleActivity.
val pendingIntent: PendingIntent = PendingIntent.getActivity(
/* context = */ context,
/* requestCode = */ 0,
/* intent = */ Intent(context, WidgetDetailsActivity::class.java),
/* flags = */ PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
// Get the layout for the widget and attach an on-click listener
// to the button.
val string="sa"
val uri:String="myUri"
var imageuri: Uri = Uri.parse(uri)
val views: RemoteViews = RemoteViews(context.packageName,R.layout.activity_widget_details).apply {
setOnClickPendingIntent(R.id.fullImageWidget, pendingIntent)
}
// Tell the AppWidgetManager to perform an update on the current
// widget.
//views.setImageViewUri(R.id.fullImageWidget,null)
views.setImageViewUri(R.id.fullImageWidget,imageuri)
appWidgetManager.updateAppWidget(appWidgetId, views)
}
}
}