【问题标题】:Create a custom album in the Android Gallery App在 Android Gallery App 中创建自定义相册
【发布时间】:2011-07-13 17:48:45
【问题描述】:

我想在 Android 中创建一个新的“专辑”。我不明白你必须用你自己的 ContentProvider 来做。但我不知道怎么做。如果您拍照,所有图像都会出现在相册“相机”中。如果您安装了 Google+,您会看到 2 个额外的相册:即时上传和个人资料图片。

我们想创造类似的东西。我们每个用户都有一个在线相册,我们希望它在相册应用中显示为相册项目。有人能指出我正确的方向吗?

我已经查过了:http://developer.android.com/guide/topics/providers/content-providers.html

其实我不确定这是否可能。

【问题讨论】:

    标签: android image gallery android-contentprovider


    【解决方案1】:

    您可以使用这种方式在图库应用中创建相册。该名称显示为“应用图片”。

    String path = Environment.getExternalStorageDirectory().toString();
    File dir = new File(path, "/appname/media/app images/");
    if (!dir.isDirectory()) {
            dir.mkdirs();
    }
    
    File file = new File(dir, filename + ".jpg");
    String imagePath =  file.getAbsolutePath();
        //scan the image so show up in album
    MediaScannerConnection.scanFile(this,
            new String[] { imagePath }, null,
            new MediaScannerConnection.OnScanCompletedListener() {
            public void onScanCompleted(String path, Uri uri) {
            if(Config.LOG_DEBUG_ENABLED) {
                Log.d(Config.LOGTAG, "scanned : " + path);
            }
            }
    });
    

    【讨论】:

    • 嗨@Angelokh,您提供的解决方案运行良好。但我有一个问题。带有 .png 的图像显示在图库中。如果将 .png 文件重命名为 .jpg,则它们将显示在图库中。我们可以在代码中做些什么来解决这个问题,或者它是画廊应用程序的默认行为吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-05
    • 2012-05-23
    • 1970-01-01
    • 2013-04-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多