我将图像添加到SDCARD上的文件夹中.由于图像和我的文件夹在图库中没有立即可见,我试图让MediaScannerConnection更新并在图库中显示文件夹/图像.这对我来说不是很好,因为Gallery中没有任何内容.我只在Eclipse AVD中测试.
我没有看到很多关于这个的讨论,因为scanFile是自api8以来的新功能.有人能说明这是怎么做的吗?
我在服务和Activity中尝试它但在onScanCompleted时继续获得uri = null.
我正在制作的这个应用程序正在拍照并将其保存到SD卡但图片未显示在库中......我的代码是否有问题
public void takepicture(View view){
try{
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
//To store public files
File directory=new File(Environment.getExternalStorageDirectory()
, "Myapp Pictures");
if(!directory.exists())
directory.mkdir();
// Create an image file name
String timeStamp =
new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "Img" + timeStamp + ".jpg";
file=new File(directory, imageFileName);
if(!file.exists())
file.createNewFile();
}
}catch(Exception e){
e.getCause();
}
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mImageUri=Uri.fromFile(file);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
startActivityForResult(takePictureIntent, actioncode);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == actioncode){
if((file.length())==0){
file.delete(); …Run Code Online (Sandbox Code Playgroud) android android-intent android-gallery android-imageview android-mediascanner
我正在开发一个基本的相机应用程序。我可以拍照,并且可以在我的应用程序中查看它。但我想在图库中异步查看我的照片。重新启动手机后,我可以在图库中看到我的照片。
示例代码。
public class PhotosActivity extends Fragment implements View.OnClickListener {
private final int REQUEST_CODE = 100;
private Button fotobutton;
private ImageView foto_image;
private static final String IMAGE_DIRECTORY_NAME = "OlkunMustafa";
public static final int MEDIA_TYPE_IMAGE = 1;
private Uri fileUri;
// Directory name to store captured images and videos
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.photos_activity,container,false);
fotobutton = (Button) rootView.findViewById(R.id.fotobutton);
foto_image = (ImageView) rootView.findViewById(R.id.foto_image);
fotobutton.setOnClickListener(this);
return rootView;
}
@Override
public void onClick(View v) { …Run Code Online (Sandbox Code Playgroud)