如何允许用户将图像上传到我的应用程序并使用它们? [英] How do I allow users to upload images to my app, and use them?

查看:119
本文介绍了如何允许用户将图像上传到我的应用程序并使用它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个应用程序,该应用程序将允许用户上传自己的图标以供在该应用程序中使用(这些图标为.png或.gif小文件).我想包括一组默认的图标,然后允许用户添加自己的图标.

I'm building an app which will allow the user to upload their own icons for use within the app (these will be small .png or .gif files). I want to include a default set of icons, and then allow the user to add their own.

我正在尝试找出最好的方法-在线上似乎有各种解决方案,但我不确定哪种方法最适合我的目的.正如我所说,我想为该应用提供一组默认的图标,以存储在用户的设备上.然后,用户应该能够添加更多图标,这些图标也应该存储在设备上(稍后,用户可以选择将图标上传到中央服务器,以便其他人也可以使用它们).

I'm trying to figure out the best way to do this - there seem to be various solutions online and I'm not sure which is best for my purposes. As I said, I'd like to supply a default set of icons with the app, to be stored on the user's device. The user should then be able to add more icons, which should also be stored on the device (at some point later on the user can choose to upload the icons to a central server so that other people can use them too).

当前,我尝试将默认的.png文件手动添加到Android Studio的可绘制"文件夹中,然后将资源ID存储在数据库中.但是,资源ID似乎一直在变化,因此大多数时候加载错误的图标.因此,我相信我需要在数据库中存储.png文件的名称/路径.那是正确的吗?如果是这样,是否有一个指向"drawable"文件夹的标准文件路径?

Currently I've tried adding the default .png files manually to Android Studio's 'drawable' folder, and then storing the resource id in the database. The resource id seems to keep changing, though, so the wrong icon is being loaded most of the time. So, instead I believe I need to store the name/path of the .png file in the database. Would that be correct? If so, is there a standard file path that leads to the 'drawable' folder?

那用户上传图标呢?我应该只将它们保存到特定目录中,然后将路径存储在数据库中吗?还是有更好的方法来解决这个问题?

And what about the user uploading icons? Should I just save these to a particular directory, and then store the path in the database? Or is there a better way to handle this?

我应该考虑什么样的事情?图标的最大尺寸应为64x64左右(我还没有完全决定,但是它们不会比这个大很多-我们谈论的不是1000x1000之类的东西).从理论上讲,用户可以根据需要添加任意数量,但实际上,我想大多数用户将使用默认设置,而少数用户会添加多达20-30个自己的图标.

What kinds of things should I be considering? The icons should be 64x64 max, or thereabouts (I haven't totally decided yet, but they won't be much bigger than that - we're not talking about 1000x1000 or anything). In theory the user can add as many as they want, but in practice I imagine most will use the default set, and a few will add up to 20-30 icons of their own.

欢迎所有建议!谢谢.

推荐答案

在此处了解有关Android内部和外部存储的信息:

Read about internal and external storage in Android here: https://developer.android.com/guide/topics/data/data-storage.html

唯一的区别是,如果用户说,请将手机插入计算机并尝试查看文件,则无法在内部存储中访问图像/数据.在外部存储中,所有项目都是公开的.

The only difference is that in internal storage the images/data is not accessible by users if they say, plug their phone into their computer and try to view the files. In external storage all items are public.

有关如何使用户在您的应用程序中保存图像的一些示例代码,请参见以下SO帖子:

For some sample code on how to have users save images in your app take a look at this SO post: Saving and Reading Bitmaps/Images from Internal memory in Android

然后,您可以仅将图标的文件名存储在共享的首选项中(如果您不希望看到太多的图标并且您的模型很简单),或者将SQLite存储在模型更复杂的情况下.由于您听起来像个初学者,所以我建议您从共享首选项开始?

You can then just store the filenames of the icons in shared preferences (if you don't anticipate that many icons and your model is simple) or SQLite if your model is more complex. Since you sound like a beginner I would recommend start with shared preferences?

对于您与应用程序一起存储的默认图标,是的,您可以将它们放在drawables文件夹中(如果要执行此操作,则在不同屏幕上具有不同的大小),但是由于您已经知道这些可绘制资源的名称,当需要时,您是否只显示想要使用Java的任何内容?我不确定将这些内容存储在数据库中的原因是什么,但是我又不知道您要构建什么.

As for the default icons you store with your app, yes you can put them in the drawables folder (with different sizes for different screens if you are doing that thing), but since you already know the names of those drawable resources can't you just display whatever one you want with Java when you need to? I am not sure what the reason would be to store those in a database but then again I have no idea what you are building.

希望这会有所帮助.

这篇关于如何允许用户将图像上传到我的应用程序并使用它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆