par*_*kos 16 java android android-intent
关注这个问题,有没有办法在没有提示用户任何东西的情况下启动android的意图?
现在,我正在检索这样的图像:
public void changeImage(View view) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser(intent, getResources().getString(R.string.select_picture)),
PICK_IMAGE);
}
Run Code Online (Sandbox Code Playgroud)
然后我存储Uri,并在必要时显示图像(我实际上首先调整它的大小,但这没关系):
Uri _uri = Uri.parse(_path);
InputStream imageStream = null;
try {
imageStream = getContentResolver().openInputStream(_uri);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Bitmap b = BitmapFactory.decodeStream(imageStream);
iv.setImageBitmap(b);
Run Code Online (Sandbox Code Playgroud)
我想通过"默默地"调用意图来获取给定其Uri的图像数据,以获得相关权限.所以我需要这样的东西:
编辑:
我试过这个setPackage()方法.此代码具有以下行为:
如果使用ACTION_VIEW意图,则会打开图库并显示特定图像.
如果使用了ACTION_GET_CONTENT意图,即使我提供了特定的Uri,也会提示我从图库中选择一个图像.
>
Uri _uri = Uri.parse(_path);
InputStream imageStream = null;
Bitmap b = null;
try {
imageStream = getContentResolver().openInputStream(_uri);
b = BitmapFactory.decodeStream(imageStream);
ImageView iv = (ImageView) findViewById(R.id.playerImage);
iv.setImageBitmap(b);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
Intent dummyIntent = new Intent(Intent.ACTION_GET_CONTENT);
//Intent dummyIntent = new Intent(Intent.ACTION_VIEW);
dummyIntent.setDataAndType(_uri,"image/*");
dummyIntent.setPackage("com.google.android.gallery3d");
startActivityForResult(dummyIntent, PICK_IMAGE);
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
一种可能的解决方案是使用“共享首选项”保存文件的 URI,而不是尝试发送“静默”意图”保存文件的 URI,而不是尝试发送“静默”意图 - 您可以将用户和 URI 保存为键/值对(例如)。
当您稍后想要打开该文件时,可以在不发送意图的情况下打开该文件。
| 归档时间: |
|
| 查看次数: |
1213 次 |
| 最近记录: |