javags(agc,"android.content.Intent","android.content.Intent.ACTION_GET_CONTENT")
javanew(it,"android.content.Intent","String",agc)
java(c,it,"android.content.Intent.setType","String","image/*")
javags(ca,"android.content.Intent","android.content.Intent.CATEGORY_OPENABLE")
java(c,it,"android.content.Intent.addCategory","String",ca)
java(c,activity,"android.app.Activity.startActivityForResult","android.content.Intent",it,"int",2)
回调事件javags(er,activity,"android.app.Activity","RESULT_OK")
f(st_lC==er)
{
f(st_sC==2)
{
java(uri,st_iT,"android.content.Intent.getData")
call(path, "mjava", "uri.getRealPath", activity, uri)
fdir(a)
ss(a+"/",a)
sr(path,a,"%",path)
us(控件id,"src",path)
}
}
uri.mjava
import android.content.ContentUris
import android.content.Intent
import android.net.Uri
import android.provider.DocumentsContract
import android.provider.MediaStore
import android.database.Cursor
import android.content.Context
public static String getRealPath(Context context, Uri uri)
{
String imagePath = null
if(DocumentsContract.isDocumentUri(context, uri))
{
String docId = DocumentsContract.getDocumentId(uri)
if ("com.android.providers.media.documents".equals(uri.getAuthority()))
{
String id = docId.split(":")[1]
String selection = MediaStore.Images.Media._ID + "=" + id
imagePath = getImagePath(context, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection)
}
else if ("com.android.providers.downloads.documents".equals(uri.getAuthority()))
{
Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(docId))
imagePath = getImagePath(context, contentUri, null)
}
}
else if("content".equalsIgnoreCase(uri.getScheme()))
{
imagePath = getImagePath(context, uri, null)
}
else if("file".equalsIgnoreCase(uri.getScheme()))
{
imagePath = uri.getPath()
}
return imagePath
}
public String getImagePath(Context context, Uri uri, String selection)
{
String path = null
Cursor cursor = context.getContentResolver().query(uri, null, selection, null, null)
if (cursor != null)
{
if (cursor.moveToFirst())
{
path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA))
}
cursor.close()
}
return path
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)