2011-07-13 31 views
5

我想在Android中创建一个新的“相册”。我不明白你必须用你自己的ContentProvider来做到这一点。但我无法弄清楚如何。如果您拍摄照片,所有图像都会显示在相册“相机”中。如果您已安装Google+,则会看到2个额外的相册:即时上传&个人资料照片。在Android Gallery应用中创建自定义相册

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

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

其实即时通讯真的不知道,如果它是可能的。

回答

7

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

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); 
     } 
     } 
}); 
+0

嗨@Angelokh您提供的解决方案工作正常。但我有一个问题。带有.png的图像显示在图库中。如果将.png文件重命名为.jpg,则它们将显示在图库中。有没有什么事情我们可以在代码中解决这个问题,或者它是默认的图库应用程序的行为? –