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);
}
}
x狰挡、Android保存圖片至相冊(cè)原生代碼
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門锌钮,熙熙樓的掌柜王于貴愁眉苦臉地迎上來桥温,“玉大人,你說我怎么就攤上這事梁丘∏纸” “怎么了旺韭?”我有些...
- 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)掏觉。 經(jīng)常有香客問我茂翔,道長(zhǎng),這世上最難降的妖魔是什么履腋? 我笑而不...
- 正文 為了忘掉前任珊燎,我火速辦了婚禮,結(jié)果婚禮上遵湖,老公的妹妹穿的比我還像新娘悔政。我一直安慰自己,他們只是感情好延旧,可當(dāng)我...
- 文/花漫 我一把揭開白布谋国。 她就那樣靜靜地躺著,像睡著了一般迁沫。 火紅的嫁衣襯著肌膚如雪芦瘾。 梳的紋絲不亂的頭發(fā)上,一...
- 文/蒼蘭香墨 我猛地睜開眼二鳄,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了媒怯?” 一聲冷哼從身側(cè)響起订讼,我...
- 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎扇苞,沒想到半個(gè)月后欺殿,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡杨拐,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年祈餐,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了擂啥。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片哄陶。...
- 正文 年R本政府宣布至扰,位于F島的核電站鳍徽,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏敢课。R本人自食惡果不足惜阶祭,卻給世界環(huán)境...
- 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望直秆。 院中可真熱鬧濒募,春花似錦、人聲如沸圾结。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽筝野。三九已至晌姚,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間歇竟,已是汗流浹背挥唠。 一陣腳步聲響...
- 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像号坡,于是被迫代替她去往敵國(guó)和親懊烤。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- Andorid保存圖片至相冊(cè)功能實(shí)現(xiàn)網(wǎng)上能搜到解決方式普遍是方式一,但是實(shí)際測(cè)試發(fā)現(xiàn)畜隶,方式一是有問題的壁肋。實(shí)現(xiàn)方式一...
- 點(diǎn)擊按鈕,將self.imageView上面的image內(nèi)容保存到本地相冊(cè)籽慢,并指定判斷保存成功與否的方法image...
- 文丨紅瑀 【系列連載】生活在臺(tái)灣(目錄) 臺(tái)灣有四大族群-閩南人浸遗、客家人、外省人與原住民箱亿,單單閩南人就占了約70%...