当前位置: 编程技术>移动开发
本页文章导读:
▪传媒信息查询 媒体信息查询
今天写了一个查询图片信息的方法,才知道android中的所有媒体信息都被android保存到数据库里了。android系统每次加载SDCARD的时候都会扫描SDCARD把sdcard中的多媒体,文件信息等.........
▪ 位与加密形式的实现 位与加密方式的实现
位与加密方式的速度非常快。若能保证其私有密钥的安全性,则位与加密的安全性很高,要破译几乎是不可能的。
但是位与加密的缺陷是灵活性较差,对私有密钥的管理是.........
▪ 可旋转器皿 可旋转容器
在个网上找到一个很好用的 RotateLayout 可以在实现各个角度的旋转,也可以用来模拟横屏,或模拟竖屏等出处:http://stackoverflow.com/questions/8047422/is-there-any-way-to-rotate-a-button-withou.........
[1]传媒信息查询
来源: 互联网 发布时间: 2014-02-18
媒体信息查询
今天写了一个查询图片信息的方法,才知道android中的所有媒体信息都被android保存到数据库里了。
android系统每次加载SDCARD的时候都会扫描SDCARD把sdcard中的多媒体,文件信息等等信息保存在数据库中。
我们先看一下数据库文件保存的目录 /data/data/com.android.providers.media/databases,在这个目录里有一个数据库文件
打开数据库,就可以看到android按着不同的数据类型给我们分成了不同的表,有image、video、auto_meta等等。
android为我们提供了很好的方法查询数据库:
/*
* 解析cursor获得其中数据
*/
1、SD卡中的所有缩略图可以通过MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI来得到
2、MediaStore.Images.Media.EXTERNAL_CONTENT_URI来得到原始图片
今天写了一个查询图片信息的方法,才知道android中的所有媒体信息都被android保存到数据库里了。
android系统每次加载SDCARD的时候都会扫描SDCARD把sdcard中的多媒体,文件信息等等信息保存在数据库中。
我们先看一下数据库文件保存的目录 /data/data/com.android.providers.media/databases,在这个目录里有一个数据库文件
打开数据库,就可以看到android按着不同的数据类型给我们分成了不同的表,有image、video、auto_meta等等。
android为我们提供了很好的方法查询数据库:
ContentResolver myResolver=this.context.getContentResolver();
Cursor cursor=myResolver.query(uri, projection, selection, selectionArgs, sortOrder);
示例代码:
/**
* 根据文件名查看图像信息,返回查询结果,包括文件路径、大小、文件名、类型、标题(文件名无扩展名)、父文件名
* @param display_name 文件名 例:pic.png
* @return 如果查询结果为空则返回null,否则返回一个ArrayList<Map<String,String>>类型数据,Map键名依次为date、size、display_name、mime_type、title、bucket_display,也可以直接使用常量ConstantFactory.ImageAbout.DATE等。
*
*/
public ArrayList<Map<String,String>> getImageInformationForDisplayName(String display_name){
ContentResolver myResolver=this.context.getContentResolver();
Cursor cursor=myResolver.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, "_display_name=?", new String[]{display_name}, null);
if(cursor.getCount()==0){
return null;
}
cursor.moveToFirst();
ArrayList<Map<String,String>> list=new ArrayList<Map<String,String>>();
Map<String, String> map=resolutionCursor(cursor);
for(int i=0;i<cursor.getCount();i++){
map=resolutionCursor(cursor);
list.add(map);
cursor.moveToNext();
}
return list;
}
/*
* 解析cursor获得其中数据
*/
private Map<String, String> resolutionCursor(Cursor cursor){
Map<String, String> map =new HashMap<String, String>();
// cursor.moveToPosition(23);
// this.string=cursor.getColumnNames();
// for(int i=0;i<string.length;i++){
// System.out.println(string[i]);
// //System.out.println(cursor.getColumnIndex(string[i]));
// System.out.println(""+cursor.getString(cursor.getColumnIndex(string[i])));
// }
//
// System.out.println(""+cursor.getString(cursor.getColumnIndex("_data"))+"\n"+ cursor.getString(cursor.getColumnIndex("_size"))
// +"\n"+cursor.getString(cursor.getColumnIndex("_display_name"))+"\n"+cursor.getString(cursor.getColumnIndex("mime_type"))
// +"\n"+cursor.getString(cursor.getColumnIndex("title"))+"\n"+cursor.getString(cursor.getColumnIndex("bucket_display_name")));
//具体的文件地址/sdcard/tencent/MobileQQ/head/511079108.png
map.put(ConstantFactory.ImageAbout.DATA, cursor.getString(cursor.getColumnIndex("_data")));
//文件大小
map.put(ConstantFactory.ImageAbout.SIZE, cursor.getString(cursor.getColumnIndex("_size")));
//文件名称(包含扩展名)
map.put(ConstantFactory.ImageAbout.DISPLAY_NAME, cursor.getString(cursor.getColumnIndex("_display_name")));
//文件类型
map.put(ConstantFactory.ImageAbout.MIME_TYPE, cursor.getString(cursor.getColumnIndex("mime_type")));
//文件标题(文件名没有标题)
map.put(ConstantFactory.ImageAbout.TITLE, cursor.getString(cursor.getColumnIndex("title")));
//父文件夹名
map.put(ConstantFactory.ImageAbout.BUCKET_DISPLAY, cursor.getString(cursor.getColumnIndex("bucket_display_name")));
return map;
}
1、SD卡中的所有缩略图可以通过MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI来得到
2、MediaStore.Images.Media.EXTERNAL_CONTENT_URI来得到原始图片
[2] 位与加密形式的实现
来源: 互联网 发布时间: 2014-02-18
位与加密方式的实现
位与加密方式的速度非常快。若能保证其私有密钥的安全性,则位与加密的安全性很高,要破译几乎是不可能的。
但是位与加密的缺陷是灵活性较差,对私有密钥的管理是个头疼的问题。
在只需要简单粗暴的加密方式的环境下,这是个不错的选择。
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
public class Encryptor {
public static byte[] encrypt(byte[] content, byte[] key) {
if (key.length == 0)
throw new IllegalArgumentException("key can not be empty!");
byte[] copy = Arrays.copyOf(content, content.length);
encrypt1(copy, key, 0);
return copy;
}
private static void encrypt1(byte[] content, byte[] key, int start) {
if (start == content.length)
return;// 递归结束条件
int end = start + key.length;
if (end >= content.length)
end = content.length;
for (int i = start; i < end; i++) {
content[i] ^= key[i - start];
}
encrypt1(content, key, end);
}
public static byte[] decrypt(byte[] content, byte[] key) {
// 异或的解密等于加密
return encrypt(content, key);
}
public static void encryptFile(File file, File output, byte[] privateKey)
throws IOException {
if(output.getParentFile()!=null)
output.getParentFile().mkdirs();
FileInputStream fis = new FileInputStream(file);
FileOutputStream fos = new FileOutputStream(output);
byte[] buffer = new byte[8192];
int realSize = -1;
try {
while ((realSize = fis.read(buffer)) != -1) {
byte[] encrypted = encrypt(buffer, privateKey);
fos.write(encrypted,0,realSize);
}
}
finally {
fos.close();
fis.close();
}
}
public static void decryptFile(File file, File output, byte[] privateKey)
throws IOException {
encryptFile(file, output, privateKey);
}
public static void main(String[] args) throws Exception {
byte[] key = "kiss".getBytes();
byte[] content = "dddefr12345adkfjsadfjladskfj".getBytes();
byte[] test = encrypt(content, key);
System.out.println(new String(test));
test = decrypt(test, key);
System.out.println(new String(test));
// encryptFile(new File("test"), new File("test2"), key);
// decryptFile(new File("test2"), new File("test3"), key);
}
}
小弟潜水好久~出来透个气。呼呼
[3] 可旋转器皿
来源: 互联网 发布时间: 2014-02-18
可旋转容器
在个网上找到一个很好用的 RotateLayout 可以在实现各个角度的旋转,也可以用来模拟横屏,或模拟竖屏等
出处:
http://stackoverflow.com/questions/8047422/is-there-any-way-to-rotate-a-button-without-using-animation-in-android-2-1
在个网上找到一个很好用的 RotateLayout 可以在实现各个角度的旋转,也可以用来模拟横屏,或模拟竖屏等
出处:
http://stackoverflow.com/questions/8047422/is-there-any-way-to-rotate-a-button-without-using-animation-in-android-2-1
最新技术文章: