1. 關於調用系統相冊的 方式
方式一、
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
該方法彈出所有可以打開圖片的工具 來提供打開的應用
方式二、
<span style="white-space:pre"> </span> Intent intent = new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
該方法直接調用系統照相冊 跳入系統相冊選擇界面
2.關於小內存手機選照片時候應用被系統 殺死的問題
在小內存手手機裏偶爾會出現一中現象就是,開發的應用在放入後臺後,不就打開就會crash,而且總是報nullpointException 很多時候都是因爲,應用的數據被系統釋放。這個是時候用到的方法一般只有一個就是恢復! (當然如果你不用靜態變量或許也可以)
/**
* 保存狀態
*/
@Override
protected void onSaveInstanceState(Bundle outState) {
<span style="white-space:pre"> </span>//存儲自己的數據
<span style="white-space:pre"> </span>outstate.putXXX()
<span style="white-space:pre"> </span>}
這個方法用來保存死之前的狀態 也就是把死之前的數據進行備份到外部存儲
/**
* 恢復狀態
*/
@Override
protected void onreStoreInstanceState(Bundle savedbudle) {
//恢復自己的數據
xxx = outstate.getXXX()
}
3.關於選圖後,打印out of memery 內存溢出錯誤,這是由於Bitmap.decode(path)方法引起的,這時候如果圖片過大,很容易內存溢出,這時候不能直接讀圖片而是要通過:
//這個方法來讀取
{ Bitmap selectedBitmap = null;
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
BitmapFactory.decodeFile(selectedPathString, opts);//這裏主要是用來計算合適的大小
opts.inSampleSize =ImageCompressUtil.computeSampleSize(opts, -1, 2048 * 2048); //這裏的2048*2048是最大尺寸
opts.inJustDecodeBounds = false;
try {
selectedBitmap = BitmapFactory.decodeFile(selectedPathString, opts);
} catch (OutOfMemoryError err) {
}
通過以上方法來讀取大圖那麼 outof memery exception 就解決了!以上都是個人的一些見解!和網上搜到的東西!分享出來希望遇到 的人能少走彎路!