保存名称截屏并具有移动时间和日期 [英] Save name for screenshots and with mobile time and date

查看:406
本文介绍了保存名称截屏并具有移动时间和日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给名字不同屏幕截图这是移动日历和时间结果的名称
请帮助..

在此先感谢。我加入我的清单文件,请看看。并请加进一步的帮助
我在做什么错

 公共类MainActivity扩展活动实现监听器{//私有静态最终诠释CAMERA_REQUEST = 0;
@覆盖
保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);
     按钮BTN =(按钮)findViewById(R.id.button1);
     btn.setOnClickListener(新OnClickListener(){   @覆盖
    公共无效的onClick(视图v){
    // TODO自动生成方法存根
     如果(v.getId()== R.id.button1){              位图的位图= takeScreenshot();            ImageView的ImageView的=(ImageView的)findViewById(R.id.imageView);
            imageView.setImageBitmap(位图);              saveBitmap(位图);
          }      }
     });}      公共位图takeScreenshot(){
          查看rootView = findViewById(android.R.id.content).getRootView();
          rootView.setDrawingCacheEnabled(真);
          返回rootView.getDrawingCache();
      }
      公共无效saveBitmap(位图位图){          尝试{              ByteArrayOutputStream字节=新ByteArrayOutputStream();
              bitmap.com preSS(Bitmap.Com pressFormat.JPEG,40字节);              日历CAL = Calendar.getInstance();
             文件f =新的文件(Environment.getExternalStorageDirectory()
                    //(cal.getTimeInMillis()+JPG));
                      +文件分割符+(cal.getTimeInMillis()+JPG));
              f.createNewFile();
              FileOutputStream中FO =新的FileOutputStream(F);
              fo.write(bytes.toByteArray());
              fo.close();
          }赶上(FileNotFoundException异常五){
              Log.e(GREC,e.getMessage(),E);
          }赶上(IOException异常五){
              Log.e(GREC,e.getMessage(),E);
          }      }
公共布尔onCreateOptionsMenu(菜单菜单){
    //充气菜单;如果是present这增加了项目操作栏。
    。getMenuInflater()膨胀(R.menu.main,菜单);
    返回true;
}
@覆盖
公共无效onGpsStatusChanged(INT事件){
    // TODO自动生成方法存根}}

这是我的清单文件:

 <?XML版本=1.0编码=UTF-8>
       <清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
       包=com.example.imagescreen
       安卓版code =1
       机器人:=的versionName1.0>
       <使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/>
       <用途-SDK
        安卓的minSdkVersion =8
        机器人:targetSdkVersion =21/>       <应用
        机器人:allowBackup =真
        机器人:图标=@绘制/ ic_launcher
         机器人:标签=@字符串/ APP_NAME
         机器人:主题=@风格/ AppTheme>
        <活动
        机器人:名字=。MainActivity
        机器人:标签=@字符串/ APP_NAME>
        &所述;意图滤光器>
        <作用机器人:名字=android.intent.action.MAIN/>        <类机器人:名字=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
        < /活性GT;
        < /用途>        < /清单>

我的logcat的:

  16 10-18:29:17.957:​​I / dalvikvm(91):日新:调整JitTable从4096到819210-18 16:29:17.997:D / PermissionCache(36):检查android.permission.READ_FRAME_BUFFER为UID = 1000 =>授予(20166美元)10-18 16:29:17.997:W /窗口管理器(91):以失败的截图(230x409)到层2100510-18 16:29:18.027:D / AndroidRuntime(527):关闭VM 10-18 16:29:18.067:D / dalvikvm(527):GC_CONCURRENT释放98K,免费480K / 2048K 77%,暂停1毫秒+ 1毫秒10-18 16:29:18.077:I / AndroidRuntime(527):注:连接线的捆扎线#3'失败10-18 16:29:18.087:D / dalvikvm(538):不晚启用CheckJNI(已上)10-18 16:29:18.128:I / ActivityManager(91):启动PROC com.example.imagescreen的活动com.example.imagescreen / .MainActivity:PID = 538 UID = 10044导报= {} 101510-18 16:29:18.377:W / NetworkManagementSocketTagger(91):setKernelCountSet(10044,1)失败,错误号-210-18 16:29:18.877:I /流程(91):发送信号。 PID:538 SIG:310-18 16:29:18.877的:I / dalvikvm(538):主题ID = 3:反应以信号310-18 16:29:19.007:I / dalvikvm(538):写的堆栈跟踪到/data/anr/traces.txt10-18 16:29:19.377:I /流程(91):发送信号。 PID:538 SIG:310-18 16:29:19.377的:I / dalvikvm(538):主题ID = 3:反应以信号310-18 16:29:19.427:I / dalvikvm(538):写的堆栈跟踪到/data/anr/traces.txt10-18 16:29:19.657:D / gralloc_goldfish(538):无仿真模拟GPU检测。10-18 16:29:19.737:I / ActivityManager(91):显示com.example.imagescreen / .MainActivity:+ 1s717ms10-18 16:29:20.367:W / NetworkManagementSocketTagger(91):setKernelCountSet(10013,0)失败,错误号-210-18 16:29:20.387:W / InputManagerService(91):对非重点客户com.android.internal.view.IInputMethodClient$Stub$Proxy@412e7248开始输入(UID = 10013 PID = 189)10-18 16:29:22.233:D / ExchangeService(391):从电子邮件应用程序收到的DeviceID:androidc25914896010-18 16:29:22.233:D / ExchangeService(391):调节账户...10-18 16:29:36.067:D / dalvikvm(538):GC_FOR_ALLOC释放113K,4%免​​费6680K / 6919K,暂停76ms10-18 16:29:36.097:I / dalvikvm堆(538):成长堆(frag的情况下),以8.153MB为1639696字节分配10-18 16:29:36.157:D / dalvikvm(538):GC_CONCURRENT释放3K,4%免​​费8278K / 8583K,暂停为6ms + 4ms的10-18 16:30:10.347:W / ThrottleService(91):无法找到IFACE rmnet0统计

我的位图:
公共无效saveBitmap(位图位图){

  {尝试
        ByteArrayOutputStream字节=新ByteArrayOutputStream();
        bitmap.com preSS(Bitmap.Com pressFormat.JPEG,40字节);
        文件f =新的文件(Environment.getExternalStorageDirectory()
                +文件分割符+test.jpg放在);
        f.createNewFile();
        FileOutputStream中FO =新的FileOutputStream(F);
        fo.write(bytes.toByteArray());
        fo.close();
    }赶上(FileNotFoundException异常五){
        Log.e(GREC,e.getMessage(),E);
    }赶上(IOException异常五){
        Log.e(GREC,e.getMessage(),E);
    }
}


解决方案

 公共无效saveBitmap(位图位图){          尝试{              ByteArrayOutputStream字节=新ByteArrayOutputStream();
              bitmap.com preSS(Bitmap.Com pressFormat.JPEG,40字节);              SimpleDateFormat的SDF =新的SimpleDateFormat(YYYYMMDD_HHMMSS);
              字符串currentDateandTime = sdf.format(新的Date());
              文件f =新的文件(Environment.getExternalStorageDirectory()
                 +文件分割符+(currentDateandTime +。JPG));
              f.createNewFile();
              FileOutputStream中FO =新的FileOutputStream(F);
              fo.write(bytes.toByteArray());
              fo.close();
          }赶上(FileNotFoundException异常五){
              Log.e(GREC,e.getMessage(),E);
          }赶上(IOException异常五){
              Log.e(GREC,e.getMessage(),E);
          }

I want to give name to different screenshots that is with the name of mobile calender and time
Please help ..

Thanks in advance. i am adding my manifest file please have a look. and please add further help What i am doing wrong

 public class MainActivity extends Activity implements Listener {

//  private static final int CAMERA_REQUEST=0;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
     Button btn=(Button)findViewById(R.id.button1);
     btn.setOnClickListener(new OnClickListener() {

   @Override
    public void onClick(View v) {
    // TODO Auto-generated method stub


     if (v.getId() == R.id.button1) {

              Bitmap bitmap = takeScreenshot();

            ImageView imageView = (ImageView)findViewById(R.id.imageView);
            imageView.setImageBitmap(bitmap);

              saveBitmap(bitmap);


          }

      }
     });}

      public Bitmap takeScreenshot() {
          View rootView = findViewById(android.R.id.content).getRootView();
          rootView.setDrawingCacheEnabled(true);
          return rootView.getDrawingCache();
      }
      public void saveBitmap(Bitmap bitmap) {

          try {

              ByteArrayOutputStream bytes = new ByteArrayOutputStream();
              bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes);

              Calendar cal=Calendar.getInstance();
             File f = new File(Environment.getExternalStorageDirectory()
                    // (cal.getTimeInMillis()+"jpg"));
                      + File.separator+ (cal.getTimeInMillis()+"jpg") );


              f.createNewFile();
              FileOutputStream fo = new FileOutputStream(f);
              fo.write(bytes.toByteArray());
              fo.close();
          } catch (FileNotFoundException e) {
              Log.e("GREC", e.getMessage(), e);
          } catch (IOException e) {
              Log.e("GREC", e.getMessage(), e);
          }







      }


public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}




@Override
public void onGpsStatusChanged(int event) {
    // TODO Auto-generated method stub

}}

This my Manifest File :

       <xml version="1.0" encoding="utf-8"?>
       <manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="com.example.imagescreen"
       android:versionCode="1"
       android:versionName="1.0" >
       <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
       <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

       <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
         android:label="@string/app_name"
         android:theme="@style/AppTheme" >
        <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        </activity>
        </application>

        </manifest>

My logcat:

10-18 16:29:17.957: I/dalvikvm(91): Jit: resizing JitTable from 4096 to 8192

10-18 16:29:17.997: D/PermissionCache(36): checking android.permission.READ_FRAME_BUFFER         for uid=1000 => granted (20166 us)

10-18 16:29:17.997: W/WindowManager(91): Failure taking screenshot for (230x409) to layer 21005

10-18 16:29:18.027: D/AndroidRuntime(527): Shutting down VM

 10-18 16:29:18.067: D/dalvikvm(527): GC_CONCURRENT freed 98K, 77% free 480K/2048K, paused 1ms+1ms

10-18 16:29:18.077: I/AndroidRuntime(527): NOTE: attach of thread 'Binder Thread #3' failed

10-18 16:29:18.087: D/dalvikvm(538): Not late-enabling CheckJNI (already on)

10-18 16:29:18.128: I/ActivityManager(91): Start proc com.example.imagescreen for activity com.example.imagescreen/.MainActivity: pid=538 uid=10044 gids={1015}

10-18 16:29:18.377: W/NetworkManagementSocketTagger(91): setKernelCountSet(10044, 1) failed with errno -2

10-18 16:29:18.877: I/Process(91): Sending signal. PID: 538 SIG: 3

10-18 16:29:18.877: I/dalvikvm(538): threadid=3: reacting to signal 3

10-18 16:29:19.007: I/dalvikvm(538): Wrote stack traces to '/data/anr/traces.txt'

10-18 16:29:19.377: I/Process(91): Sending signal. PID: 538 SIG: 3

10-18 16:29:19.377: I/dalvikvm(538): threadid=3: reacting to signal 3

10-18 16:29:19.427: I/dalvikvm(538): Wrote stack traces to '/data/anr/traces.txt'

10-18 16:29:19.657: D/gralloc_goldfish(538): Emulator without GPU emulation detected.

10-18 16:29:19.737: I/ActivityManager(91): Displayed com.example.imagescreen/.MainActivity: +1s717ms

10-18 16:29:20.367: W/NetworkManagementSocketTagger(91): setKernelCountSet(10013, 0) failed with errno -2

10-18 16:29:20.387: W/InputManagerService(91): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@412e7248 (uid=10013 pid=189)

10-18 16:29:22.233: D/ExchangeService(391): Received deviceId from Email app: androidc259148960

10-18 16:29:22.233: D/ExchangeService(391): Reconciling accounts...

10-18 16:29:36.067: D/dalvikvm(538): GC_FOR_ALLOC freed 113K, 4% free 6680K/6919K, paused 76ms

10-18 16:29:36.097: I/dalvikvm-heap(538): Grow heap (frag case) to 8.153MB for 1639696-byte allocation

10-18 16:29:36.157: D/dalvikvm(538): GC_CONCURRENT freed 3K, 4% free 8278K/8583K, paused 6ms+4ms

10-18 16:30:10.347: W/ThrottleService(91): unable to find stats for iface rmnet0

my bitmap: public void saveBitmap(Bitmap bitmap) {

    try {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
        File f = new File(Environment.getExternalStorageDirectory()
                + File.separator + "test.jpg");
        f.createNewFile();
        FileOutputStream fo = new FileOutputStream(f);
        fo.write(bytes.toByteArray());
        fo.close();
    } catch (FileNotFoundException e) {
        Log.e("GREC", e.getMessage(), e);
    } catch (IOException e) {
        Log.e("GREC", e.getMessage(), e);
    }
}

解决方案

public void saveBitmap(Bitmap bitmap) {

          try {

              ByteArrayOutputStream bytes = new ByteArrayOutputStream();
              bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes);

              SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
              String currentDateandTime = sdf.format(new Date());
              File f = new File(Environment.getExternalStorageDirectory()
                 + File.separator+ (currentDateandTime+".jpg") );


              f.createNewFile();
              FileOutputStream fo = new FileOutputStream(f);
              fo.write(bytes.toByteArray());
              fo.close();
          } catch (FileNotFoundException e) {
              Log.e("GREC", e.getMessage(), e);
          } catch (IOException e) {
              Log.e("GREC", e.getMessage(), e);
          }

这篇关于保存名称截屏并具有移动时间和日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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