英文:
How to fetch image from local computer with Picasso then display it to android app with Java
问题
这行代码可以正常工作
Picasso.with(context).load("https://www.simplifiedcoding.net/wp-content/uploads/2015/10/advertise.png").into(holder.imageView);
这行代码无法正常工作
Picasso.with(context).load("/Users/jz/Desktop/Pictures/kigali.png").into(holder.imageView);
我该如何解决这个问题?
是文件权限问题吗?
英文:
This line of code works
Picasso.with(context).load("https://www.simplifiedcoding.net/wp-content/uploads/2015/10/advertise.png").into(holder.imageView);
This line of code doesn't work
Picasso.with(context).load("/Users/jz/Desktop/Pictures/kigali.png").into(holder.imageView);
How can is solve the issue ?
is it my file permission ?
答案1
得分: 3
这样做不起作用。您的计算机对于您的Android设备来说不是本地的 - 即使在模拟器上运行您的应用程序,该模拟器在计算机上运行的虚拟机,因此在此上下文中需要被视为独立设备。要使计算机上的任何文件可用,您需要使用任何服务器(如apach、nginx),并使计算机能够从网络访问(可能仅为本地)。然后,您可以使用网络访问这些文件,例如通过与您已有的相同类型的 http://
请求。
英文:
This won't work. Your computer is NOT local for your Android - even if you run your app on emulator running on that computer as it runs virtual machine thus needs to be considered separate device in this context. To make any file from your machine available you need any server (like apach, nginx) and make your computer reachable from the network (can be local only). Then you can reach these files using network i. e. via same type of http://
request you already have.
答案2
得分: 0
如果您想在应用程序中使用图像或图标,您可以将其放入资产文件夹并按以下方式使用:
Picasso.with(context).load(R.drawable.icon_main_page).into(holder.imageView)
英文:
if you want to use image or icon inside app you can put it into assets folder and use like this
Picasso.with(context).load(R.drowable.icon_main_page).into(holder.imageView)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论