在android level 19之後,由於官方更新了uri的格式,因此需要採用最新的uri解析方式以適配,
如果還採用android 4.4之前的解析方法(實際上目前網路上大部分還是這種方式)就會出現空指標的問題,實際上就是因為格式不匹配導致的解析失敗。
參考實現如下,可以直接作為工具類加入現有**中。
/**
* get the image/file path, able to run on devices above level 19
*@param activity
*@param imageuri
*/@targetapi(19)
public
static string getimageabsolutepath(activity context, uri imageuri)
} else
if (isdownloadsdocument(imageuri)) else
if (ismediadocument(imageuri)) else
if ("video".equals(type)) else
if ("audio".equals(type))
string selection = mediastore.images.media._id + "=?";
string selectionargs = new string ;
return getdatacolumn(context, contenturi, selection, selectionargs);
} } // mediastore (and general)
else
if ("content".equalsignorecase(imageuri.getscheme()))
// file
else
if ("file".equalsignorecase(imageuri.getscheme()))
return
null;
} public
static string getdatacolumn(context context, uri uri, string selection, string selectionargs) ;
try
} finally
return
null;
} /**
*@param uri the uri to check.
*@return whether the uri authority is externalstorageprovider.
*/public
static
boolean
i***ternalstoragedocument(uri uri)
/**
*@param uri the uri to check.
*@return whether the uri authority is downloadsprovider.
*/public
static
boolean
isdownloadsdocument(uri uri)
/**
*@param uri the uri to check.
*@return whether the uri authority is mediaprovider.
*/public
static
boolean
ismediadocument(uri uri)
/**
*@param uri the uri to check.
*@return whether the uri authority is google photos.
*/public
static
boolean
isgooglephotosuri(uri uri)
spring security 配置及解析
class com.test.security.service.helloserviceimpl class org.springframework.context.support.reloadableresourcebundlemessagesource expression execution ...
Session解析及執行
當瀏覽器訪問伺服器時 會將本地的cookie傳送過去,其中有乙個鍵值位jsessionid 32位16進製制數的值,伺服器會根據該值去session池查詢session物件,以此判斷是否 為一次會話,即同一使用者。當第一次訪問伺服器時不傳送cookie,伺服器會建立乙個session物件,將其對應的...
DNS解析及優化
前面的話 我們都知道tcp ip中使用的是套接字 ip位址與埠號 來進行tcp連線,那為什麼不使用網域名稱來直接通訊呢?原因有以下兩點 hosts檔案 在說dns之前,必須提乙個hosts檔案。hosts檔案作用 網域名稱和ip的對應關係儲存在乙個叫hosts檔案中。最初,通過網際網路資訊中心來管理...