Android 使用日期和数字将图像存储到SD卡中

Android 使用日期和数字将图像存储到SD卡中,android,android-sdcard,Android,Android Sdcard,我正在使用自定义相机拍摄图像,并使用datetime将其保存到sd卡中,如下所示: // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss") .format(new Date()); File mediaFile; mediaFile = new File(mediaStorageDir.getPath() + File.separator

我正在使用自定义相机拍摄图像,并使用datetime将其保存到sd卡中,如下所示:

// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
                .format(new Date());
File mediaFile;
mediaFile = new File(mediaStorageDir.getPath() + File.separator
                + "IMG_" + timeStamp + ".jpg");
return mediaFile;
IMG_20140312_162137.jpg
但我必须对文件名做一个小的更改,如现有名称如下所示:

// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
                .format(new Date());
File mediaFile;
mediaFile = new File(mediaStorageDir.getPath() + File.separator
                + "IMG_" + timeStamp + ".jpg");
return mediaFile;
IMG_20140312_162137.jpg
现在我想无论何时用户开始拍摄图像,都需要从001开始计数


对于1图像IMG_20140312_001.jpg的示例,对于2图像IMG\u 20140312\u 002.jpg等等。

然后将图像计数存储在一个共享首选项中,当您单击任何图片编号时计数增加,然后再次为下次更新共享首选项很简单,因为如果您从堆栈中清除应用程序,那么下次计数必须从最后一个开始,这就是我们使用共享的原因首选项

然后将图像计数存储在一个共享首选项中,当您单击任何图片编号时计数会增加,然后再次为下次更新共享首选项很简单,因为如果您从堆栈中清除应用程序,那么下次此计数必须从最后一次开始,这就是为什么我们使用共享首选项

然后将图像计数存储在一个共享中首选项和计数随着您单击任何图片编号而增加,然后再次更新共享首选项以备下次使用,这很简单,因为如果您从堆栈中清除应用程序,则下次此计数必须从最后一次开始,这就是为什么我们使用共享首选项的原因,然后将图像计数存储在一个共享首选项中,并随着您单击任何图片编号而增加计数图片,然后再次为下次更新共享首选项很简单,因为如果你从堆栈中清除你的应用程序,那么下次此计数必须从最后一次开始,这就是为什么我们使用共享首选项的原因,请在你的图像名称末尾添加一个计数器,如下所示:

 int count=0;
 String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
            .format(new Date());
    File mediaFile;
    mediaFile = new File(mediaStorageDir.getPath() + File.separator
            + "IMG_" + timeStamp +" _00 "+ count +".jpg");
     count++;

    return mediaFile;

在图像名称末尾附加一个计数器,如下所示:

 int count=0;
 String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
            .format(new Date());
    File mediaFile;
    mediaFile = new File(mediaStorageDir.getPath() + File.separator
            + "IMG_" + timeStamp +" _00 "+ count +".jpg");
     count++;

    return mediaFile;

在图像名称末尾附加一个计数器,如下所示:

 int count=0;
 String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
            .format(new Date());
    File mediaFile;
    mediaFile = new File(mediaStorageDir.getPath() + File.separator
            + "IMG_" + timeStamp +" _00 "+ count +".jpg");
     count++;

    return mediaFile;

在图像名称末尾附加一个计数器,如下所示:

 int count=0;
 String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
            .format(new Date());
    File mediaFile;
    mediaFile = new File(mediaStorageDir.getPath() + File.separator
            + "IMG_" + timeStamp +" _00 "+ count +".jpg");
     count++;

    return mediaFile;

为此,当应用程序重新打开时,您需要使用共享首选项跟踪计数器

SharedPreferences pref;

    SharedPreferences.Editor edit;

        pref = context.getSharedPreferences("counter", 
                Context.MODE_PRIVATE);
        edit = pref.edit();

edit.putInt("count" ,count++);
edit.commit();


and the get the count when next time you use the count

mediaFile = new File(mediaStorageDir.getPath() + File.separator
                + "IMG_" + timeStamp +pref.getString("count", 0))+ ".jpg");

为此,当应用程序重新打开时,您需要使用共享首选项跟踪计数器

SharedPreferences pref;

    SharedPreferences.Editor edit;

        pref = context.getSharedPreferences("counter", 
                Context.MODE_PRIVATE);
        edit = pref.edit();

edit.putInt("count" ,count++);
edit.commit();


and the get the count when next time you use the count

mediaFile = new File(mediaStorageDir.getPath() + File.separator
                + "IMG_" + timeStamp +pref.getString("count", 0))+ ".jpg");

为此,当应用程序重新打开时,您需要使用共享首选项跟踪计数器

SharedPreferences pref;

    SharedPreferences.Editor edit;

        pref = context.getSharedPreferences("counter", 
                Context.MODE_PRIVATE);
        edit = pref.edit();

edit.putInt("count" ,count++);
edit.commit();


and the get the count when next time you use the count

mediaFile = new File(mediaStorageDir.getPath() + File.separator
                + "IMG_" + timeStamp +pref.getString("count", 0))+ ".jpg");

为此,当应用程序重新打开时,您需要使用共享首选项跟踪计数器

SharedPreferences pref;

    SharedPreferences.Editor edit;

        pref = context.getSharedPreferences("counter", 
                Context.MODE_PRIVATE);
        edit = pref.edit();

edit.putInt("count" ,count++);
edit.commit();


and the get the count when next time you use the count

mediaFile = new File(mediaStorageDir.getPath() + File.separator
                + "IMG_" + timeStamp +pref.getString("count", 0))+ ".jpg");
“999”之后会发生什么?最好将其保留为“1,2,3…”而不是“001002003…”“999”之后会发生什么?最好将其保留为“1,2,3…”而不是“001002003…”“999”之后会发生什么?最好将其保留为“1,2,3…”而不是“001002003…”“999”之后会发生什么?最好将其保留为“1,2,3…”而不是“001002003…”惊人的解决方案bro:)事实上你应该为这个惊人的解决方案获得+1000 bro:)事实上你应该为这个惊人的解决方案获得+1000 bro:)事实上你为这个惊人的解决方案获得+1000 bro:)事实上你应该为这个解决方案获得+1000