我正在处理小部件,我需要在AppWidgetProvider中使用这个views.setImageViewResource方法,但是这个方法需要整数,但是我有URI,我该如何解决这个问题?
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)
}
}
}
1条答案
按热度按时间rggaifut1#
如果您的URI属于此类型:第一个月
所以你在你的项目中使用这段代码。它会对你有帮助。
或
如果您的URI属于此类型:
https://url.image.jpg
因此,在项目中使用Glide库加载图像。