package com.xxx.NativeCode;import android.app.AlertDialog;import android.content.Context;import android.content.Intent;import android.net.Uri;import android.os.Environment;import android.text.format.Time;import com.unity3d.player.UnityPlayer;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;/** * Created by wanshichen on 2017/3/16. */public class NativeCodeHandle {    public static void SaveImageToAlbum(String fromPath) {        Time t = new Time();        t.setToNow();        final String toPath = Environment.getExternalStorageDirectory() + String.format("/DCIM/Camera/IMG_xxx_%d%d%d_%d%d%d.jpg", t.year, t.month, t.monthDay, t.hour, t.minute, t.second);        CopyFileTo(fromPath, toPath);        UnityPlayer.currentActivity.runOnUiThread(new Runnable() {            @Override            public void run() {                scanPhotos(toPath, UnityPlayer.currentActivity);                AlertDialog.Builder builder = new AlertDialog.Builder(UnityPlayer.currentActivity)                        .setTitle("提示")                        .setMessage("保存成功")                        .setPositiveButton("确定", null);                builder.show();            }        });    }    public static void CopyFileTo(String fromPath, String toPath) {        FileInputStream fis = null;        FileOutputStream fos = null;        try {            fis = new FileInputStream(fromPath);            fos = new FileOutputStream(toPath);            byte[] buffer = new byte[1024];            int byteread = 0;            while ((byteread = fis.read(buffer)) != -1) {                fos.write(buffer, 0, byteread);            }        } catch (Exception e) {            e.printStackTrace();        } finally {            try {                if (fis != null) {                    fis.close();                }                if (fos != null) {                    fos.close();                }            } catch (IOException e) {                e.printStackTrace();            }        }    }    public static void scanPhotos(String filePath, Context context) {        Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);        intent.setData(Uri.fromFile(new File(filePath)));        context.sendBroadcast(intent);    }}

更多相关文章

  1. 大图片文件压缩保存本地,返回本地url
  2. Android安卓长按ImageView保存图片到相册
  3. Unity_打包Android提示找不到jdk解决方案
  4. android app 捕获全局异常,保存成文件
  5. android练习一之保存用户名
  6. Android_rom存储,sp存储,sdcard存储
  7. unity3d 调用 android sdk 接入
  8. 保存数据到手机内存代码优化(QQ登录保存密码)
  9. Android(安卓)电视退出程序Animation

随机推荐

  1. Android(安卓)Notification的基本使用和
  2. Android下实现数据绑定功能
  3. Android(安卓)面向接口编程
  4. android 对话框模板布局之一
  5. 让android的LogCat支持中文输出
  6. android 从SIM卡获取联系人信息
  7. ScrollView 如何恒显示滚动条
  8. [置顶] android studio 如何进行格式化代
  9. Android 7.0调用相机拍照,返回后显示拍照
  10. android 写布局的时候注意大小写