whenever i try to get uri from Intent which just select an image from image picker its not working here is my code. Please answer ASAP
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.share) {
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
i.setType("image/*");
startActivityForResult(i, 1);
} else if (id == R.id.logOut) {
ParseUser.logOut();
Intent i = new Intent(this, MainActivity.class);
startActivity(i);
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1 && resultCode == Activity.RESULT_OK && data!=null) {
try {
Uri selectedImage = data.getData();
// this is the line which is causing error
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImage);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
Toast.makeText(getApplication().getBaseContext(),"test",Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
}
}
and this is logs: I/Error: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/27 from pid=5506, uid=10043 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
permission already given are: uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
Note:can't use proper tags for uses-permisson here because stackover flow giving error
Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="Share Pics"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="X6I00RcSXvAnvvV8iaR6ftEsHo2o7sHXmzkZlb03" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="MyKnxnrPXRan1z56fpSmkxPx7hgcM44NfvzdC4q5" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".UserList" />
<activity
android:name=".UsersFeed"
android:label="@string/title_activity_users_feed"
android:parentActivityName=".UserList"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.anshuman.myinstagram.UserList"/>``
</activity>
</application>