我在Android中使用意圖列出我的應用程序時,我選擇Bitmoji應用程序中的bitmoji。然後它應該啓動我的應用程序並在ImageView中顯示bitmoji。無法獲取bitmoji圖像顯示在ImageView中從意圖Android
它啓動我的應用程序很好,但imageView是空白的。
我得到以下錯誤:
E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.bitstrips.imoji/cache/bitmoji-1441479250.png: open failed: EACCES (Permission denied)
這裏是我的MainActivity代碼:
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
private Bitmap bitmap;
private ImageView mImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mImageView = (ImageView) findViewById(R.id.imageView);
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
handleSendText(intent); // Handle text being sent
} else if (type.startsWith("image/")) {
handleSendImage(intent); // Handle single image being sent
}
}
}
void handleSendImage(Intent intent) {
Uri imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
Context context = getApplicationContext();
String selectedImagePath;
selectedImagePath = getPath(imageUri);
Toast.makeText(context, selectedImagePath, Toast.LENGTH_LONG).show();
if(imageUri!=null) {
new imageWorkerTask().execute(selectedImagePath);
}
}
public String getPath(Uri uri)
{
/*
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
cursor.moveToFirst();
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
return cursor.getString(idx);
*/
return uri.getPath();
}
class imageWorkerTask extends AsyncTask<String, Void, Bitmap> {
BitmapFactory.Options options = new BitmapFactory.Options();
Resources resources = getResources();
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;
String imageType = options.outMimeType;
@Override
protected Bitmap doInBackground(String... paths) {
return decodeBitmapFromFile(paths[0]);
}
@Override
protected void onPostExecute(Bitmap result) {
mImageView.setImageBitmap(result);
}
}
public static Bitmap decodeBitmapFromFile(String path) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
// Calculate inSampleSize
//options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
}
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(path, options);
}
我能夠加載從資源(從我的可繪製文件夾)到imageView的圖像。這是特別是當我試圖從另一個應用程序(bitmoji),圖像視圖不更新的圖像。 – Alex