API 26 runtime permission & android.os.FileUriExposedException
up vote
-1
down vote
favorite
My app needs below permissions. Which has been incorporated in AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.autofocus"/>
After upgrading to API 26
(targetSdkVersion 26)
Some functionality is not working. As I need to incorporate runtime permission. I am using RxPermission .
The problem is my most of the implementations are placed in helper class(not inside main activity).
when I am trying to use helper library getting error - .
I have tried with the following options too -
RxPermissions rxPermissions = new RxPermissions((FragmentActivity) mContext);
As RxPermission require Fragment as target.Can we ask user all the permission in the main activity? A sample code will help me. Project code for reference
[Fixed]
Now I am calling from the activity. ReferenceCode changed -
RxPermissions rxPermissions=new RxPermissions(this);
rxPermissions.request(Manifest.permission.CAMERA)
.subscribe(granted -> {
if (granted) {
//LogUtil.e(LOG_TAG, "Granted external permission");
setContentView(R.layout.activity_local_album);
ViewGroup backGround = (ViewGroup) findViewById(R.id.background);
MyUtil.setBackgroundBlur(backGround, this);
initAdapter();
assignViews();
} else {
// Oups permission denied
}
});
[New error]
I am getting android.os.FileUriExposedException:
error. Code:
public void onClick(View v) {
switch (v.getId()) {
// 返回
case R.id.action_back:
myFinish();
break;
// 拍照
case R.id.action_capture:
PackageManager pm = getPackageManager();
// FEATURE_CAMERA - 后置相机
// FEATURE_CAMERA_FRONT - 前置相机
if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)) {
// 访问相机类型
int requestType;
// 截取主题壁纸
if (mRequestType != 2) {
requestType = REQUEST_IMAGE_CAPTURE_THEME;
} else { // 截取二维码logo
requestType = REQUEST_IMAGE_CAPTURE_QRCODE_LOGO;
}
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mImageUri = Uri.fromFile(MyUtil.getFileDirectory(this, "/Android/data/" +
getPackageName() + "/capture/temporary.jpg"));
intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
startActivityForResult(intent, requestType);
overridePendingTransition(0, R.anim.zoomin);
}
Error
Process: com.bisw.weac, PID: 20997
android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.bisw.weac/capture/temporary.jpg exposed beyond app through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1958)
at android.net.Uri.checkFileUriExposed(Uri.java:2356)
at android.content.ClipData.prepareToLeaveProcess(ClipData.java:944)
at android.content.Intent.prepareToLeaveProcess(Intent.java:10480)
at android.content.Intent.prepareToLeaveProcess(Intent.java:10465)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1616)
at android.app.Activity.startActivityForResult(Activity.java:4564)
at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:68)
at android.app.Activity.startActivityForResult(Activity.java:4522)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:751)
at com.bisw.weac.activities.LocalAlbumActivity.onClick(LocalAlbumActivity.java:222)
at android.view.View.performClick(View.java:6877)
at android.widget.TextView.performClick(TextView.java:12651)
at android.view.View$PerformClick.run(View.java:26069)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
android android-layout android-fragments android-fragmentactivity rxpermissions
add a comment |
up vote
-1
down vote
favorite
My app needs below permissions. Which has been incorporated in AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.autofocus"/>
After upgrading to API 26
(targetSdkVersion 26)
Some functionality is not working. As I need to incorporate runtime permission. I am using RxPermission .
The problem is my most of the implementations are placed in helper class(not inside main activity).
when I am trying to use helper library getting error - .
I have tried with the following options too -
RxPermissions rxPermissions = new RxPermissions((FragmentActivity) mContext);
As RxPermission require Fragment as target.Can we ask user all the permission in the main activity? A sample code will help me. Project code for reference
[Fixed]
Now I am calling from the activity. ReferenceCode changed -
RxPermissions rxPermissions=new RxPermissions(this);
rxPermissions.request(Manifest.permission.CAMERA)
.subscribe(granted -> {
if (granted) {
//LogUtil.e(LOG_TAG, "Granted external permission");
setContentView(R.layout.activity_local_album);
ViewGroup backGround = (ViewGroup) findViewById(R.id.background);
MyUtil.setBackgroundBlur(backGround, this);
initAdapter();
assignViews();
} else {
// Oups permission denied
}
});
[New error]
I am getting android.os.FileUriExposedException:
error. Code:
public void onClick(View v) {
switch (v.getId()) {
// 返回
case R.id.action_back:
myFinish();
break;
// 拍照
case R.id.action_capture:
PackageManager pm = getPackageManager();
// FEATURE_CAMERA - 后置相机
// FEATURE_CAMERA_FRONT - 前置相机
if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)) {
// 访问相机类型
int requestType;
// 截取主题壁纸
if (mRequestType != 2) {
requestType = REQUEST_IMAGE_CAPTURE_THEME;
} else { // 截取二维码logo
requestType = REQUEST_IMAGE_CAPTURE_QRCODE_LOGO;
}
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mImageUri = Uri.fromFile(MyUtil.getFileDirectory(this, "/Android/data/" +
getPackageName() + "/capture/temporary.jpg"));
intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
startActivityForResult(intent, requestType);
overridePendingTransition(0, R.anim.zoomin);
}
Error
Process: com.bisw.weac, PID: 20997
android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.bisw.weac/capture/temporary.jpg exposed beyond app through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1958)
at android.net.Uri.checkFileUriExposed(Uri.java:2356)
at android.content.ClipData.prepareToLeaveProcess(ClipData.java:944)
at android.content.Intent.prepareToLeaveProcess(Intent.java:10480)
at android.content.Intent.prepareToLeaveProcess(Intent.java:10465)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1616)
at android.app.Activity.startActivityForResult(Activity.java:4564)
at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:68)
at android.app.Activity.startActivityForResult(Activity.java:4522)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:751)
at com.bisw.weac.activities.LocalAlbumActivity.onClick(LocalAlbumActivity.java:222)
at android.view.View.performClick(View.java:6877)
at android.widget.TextView.performClick(TextView.java:12651)
at android.view.View$PerformClick.run(View.java:26069)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
android android-layout android-fragments android-fragmentactivity rxpermissions
I'm assuming the library requires aFragmentActivity
instance, which you are not supplying - yourmContext
is theApplication
looking at your naming of the parameter. Consider passing the correctContext
on the method calls inside your helper, not the constructor, as they should have a short lived scope you won't want to hold a reference to.
– Mark Keen
2 days ago
Thanks @mark-keen. I am calling the helper class like this LocalAlbumImagePickerHelper.getInstance(LocalAlbumActivity.this). Do you want me to change here?
– Biswajit Das
2 days ago
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
My app needs below permissions. Which has been incorporated in AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.autofocus"/>
After upgrading to API 26
(targetSdkVersion 26)
Some functionality is not working. As I need to incorporate runtime permission. I am using RxPermission .
The problem is my most of the implementations are placed in helper class(not inside main activity).
when I am trying to use helper library getting error - .
I have tried with the following options too -
RxPermissions rxPermissions = new RxPermissions((FragmentActivity) mContext);
As RxPermission require Fragment as target.Can we ask user all the permission in the main activity? A sample code will help me. Project code for reference
[Fixed]
Now I am calling from the activity. ReferenceCode changed -
RxPermissions rxPermissions=new RxPermissions(this);
rxPermissions.request(Manifest.permission.CAMERA)
.subscribe(granted -> {
if (granted) {
//LogUtil.e(LOG_TAG, "Granted external permission");
setContentView(R.layout.activity_local_album);
ViewGroup backGround = (ViewGroup) findViewById(R.id.background);
MyUtil.setBackgroundBlur(backGround, this);
initAdapter();
assignViews();
} else {
// Oups permission denied
}
});
[New error]
I am getting android.os.FileUriExposedException:
error. Code:
public void onClick(View v) {
switch (v.getId()) {
// 返回
case R.id.action_back:
myFinish();
break;
// 拍照
case R.id.action_capture:
PackageManager pm = getPackageManager();
// FEATURE_CAMERA - 后置相机
// FEATURE_CAMERA_FRONT - 前置相机
if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)) {
// 访问相机类型
int requestType;
// 截取主题壁纸
if (mRequestType != 2) {
requestType = REQUEST_IMAGE_CAPTURE_THEME;
} else { // 截取二维码logo
requestType = REQUEST_IMAGE_CAPTURE_QRCODE_LOGO;
}
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mImageUri = Uri.fromFile(MyUtil.getFileDirectory(this, "/Android/data/" +
getPackageName() + "/capture/temporary.jpg"));
intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
startActivityForResult(intent, requestType);
overridePendingTransition(0, R.anim.zoomin);
}
Error
Process: com.bisw.weac, PID: 20997
android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.bisw.weac/capture/temporary.jpg exposed beyond app through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1958)
at android.net.Uri.checkFileUriExposed(Uri.java:2356)
at android.content.ClipData.prepareToLeaveProcess(ClipData.java:944)
at android.content.Intent.prepareToLeaveProcess(Intent.java:10480)
at android.content.Intent.prepareToLeaveProcess(Intent.java:10465)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1616)
at android.app.Activity.startActivityForResult(Activity.java:4564)
at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:68)
at android.app.Activity.startActivityForResult(Activity.java:4522)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:751)
at com.bisw.weac.activities.LocalAlbumActivity.onClick(LocalAlbumActivity.java:222)
at android.view.View.performClick(View.java:6877)
at android.widget.TextView.performClick(TextView.java:12651)
at android.view.View$PerformClick.run(View.java:26069)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
android android-layout android-fragments android-fragmentactivity rxpermissions
My app needs below permissions. Which has been incorporated in AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.autofocus"/>
After upgrading to API 26
(targetSdkVersion 26)
Some functionality is not working. As I need to incorporate runtime permission. I am using RxPermission .
The problem is my most of the implementations are placed in helper class(not inside main activity).
when I am trying to use helper library getting error - .
I have tried with the following options too -
RxPermissions rxPermissions = new RxPermissions((FragmentActivity) mContext);
As RxPermission require Fragment as target.Can we ask user all the permission in the main activity? A sample code will help me. Project code for reference
[Fixed]
Now I am calling from the activity. ReferenceCode changed -
RxPermissions rxPermissions=new RxPermissions(this);
rxPermissions.request(Manifest.permission.CAMERA)
.subscribe(granted -> {
if (granted) {
//LogUtil.e(LOG_TAG, "Granted external permission");
setContentView(R.layout.activity_local_album);
ViewGroup backGround = (ViewGroup) findViewById(R.id.background);
MyUtil.setBackgroundBlur(backGround, this);
initAdapter();
assignViews();
} else {
// Oups permission denied
}
});
[New error]
I am getting android.os.FileUriExposedException:
error. Code:
public void onClick(View v) {
switch (v.getId()) {
// 返回
case R.id.action_back:
myFinish();
break;
// 拍照
case R.id.action_capture:
PackageManager pm = getPackageManager();
// FEATURE_CAMERA - 后置相机
// FEATURE_CAMERA_FRONT - 前置相机
if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)) {
// 访问相机类型
int requestType;
// 截取主题壁纸
if (mRequestType != 2) {
requestType = REQUEST_IMAGE_CAPTURE_THEME;
} else { // 截取二维码logo
requestType = REQUEST_IMAGE_CAPTURE_QRCODE_LOGO;
}
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mImageUri = Uri.fromFile(MyUtil.getFileDirectory(this, "/Android/data/" +
getPackageName() + "/capture/temporary.jpg"));
intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
startActivityForResult(intent, requestType);
overridePendingTransition(0, R.anim.zoomin);
}
Error
Process: com.bisw.weac, PID: 20997
android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.bisw.weac/capture/temporary.jpg exposed beyond app through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1958)
at android.net.Uri.checkFileUriExposed(Uri.java:2356)
at android.content.ClipData.prepareToLeaveProcess(ClipData.java:944)
at android.content.Intent.prepareToLeaveProcess(Intent.java:10480)
at android.content.Intent.prepareToLeaveProcess(Intent.java:10465)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1616)
at android.app.Activity.startActivityForResult(Activity.java:4564)
at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:68)
at android.app.Activity.startActivityForResult(Activity.java:4522)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:751)
at com.bisw.weac.activities.LocalAlbumActivity.onClick(LocalAlbumActivity.java:222)
at android.view.View.performClick(View.java:6877)
at android.widget.TextView.performClick(TextView.java:12651)
at android.view.View$PerformClick.run(View.java:26069)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
android android-layout android-fragments android-fragmentactivity rxpermissions
android android-layout android-fragments android-fragmentactivity rxpermissions
edited yesterday
asked 2 days ago
Biswajit Das
307417
307417
I'm assuming the library requires aFragmentActivity
instance, which you are not supplying - yourmContext
is theApplication
looking at your naming of the parameter. Consider passing the correctContext
on the method calls inside your helper, not the constructor, as they should have a short lived scope you won't want to hold a reference to.
– Mark Keen
2 days ago
Thanks @mark-keen. I am calling the helper class like this LocalAlbumImagePickerHelper.getInstance(LocalAlbumActivity.this). Do you want me to change here?
– Biswajit Das
2 days ago
add a comment |
I'm assuming the library requires aFragmentActivity
instance, which you are not supplying - yourmContext
is theApplication
looking at your naming of the parameter. Consider passing the correctContext
on the method calls inside your helper, not the constructor, as they should have a short lived scope you won't want to hold a reference to.
– Mark Keen
2 days ago
Thanks @mark-keen. I am calling the helper class like this LocalAlbumImagePickerHelper.getInstance(LocalAlbumActivity.this). Do you want me to change here?
– Biswajit Das
2 days ago
I'm assuming the library requires a
FragmentActivity
instance, which you are not supplying - your mContext
is the Application
looking at your naming of the parameter. Consider passing the correct Context
on the method calls inside your helper, not the constructor, as they should have a short lived scope you won't want to hold a reference to.– Mark Keen
2 days ago
I'm assuming the library requires a
FragmentActivity
instance, which you are not supplying - your mContext
is the Application
looking at your naming of the parameter. Consider passing the correct Context
on the method calls inside your helper, not the constructor, as they should have a short lived scope you won't want to hold a reference to.– Mark Keen
2 days ago
Thanks @mark-keen. I am calling the helper class like this LocalAlbumImagePickerHelper.getInstance(LocalAlbumActivity.this). Do you want me to change here?
– Biswajit Das
2 days ago
Thanks @mark-keen. I am calling the helper class like this LocalAlbumImagePickerHelper.getInstance(LocalAlbumActivity.this). Do you want me to change here?
– Biswajit Das
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
My app needs below permissions
Note that your app cannot hold MOUNT_UNMOUNT_FILESYTEMS
unless it is signed by the firmware signing key or is installed on the privileged app partition (mostly for rooted devices).
Can we ask user all the permission in the main activity?
You do not have a choice, according to the documentation. According to those instructions, RxPermissions only works if you request the permissions from onCreate()
of your Activity
(or possibly onCreate()
of your Fragment
, though that part is unclear).
A sample code will help me
In addition to documentation, the RxPermissions GitHub repository has a sample app. Here is the v0.9.3 edition of that sample app.
@CommnsWare thanks for clarification. Last point as I said I can do easily from the activity. But I need to refer fragment. from helper class where I don't have fragment.
– Biswajit Das
2 days ago
@BiswajitDas: By the time you callgetThumbnail()
from anywhere, you need to ensure that you have your runtime permission. Then, you do not need anRxPermissions
instance ingetThumbnail()
. Your "helper" class appears to be a singleton; a singleton cannot and should not be attempting to request runtime permissions.
– CommonsWare
2 days ago
@CommnsWare friend inside main activity I am still getting the same error - Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/thumbnails from pid=25888, uid=10229 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
– Biswajit Das
2 days ago
@BiswajitDas: Perhaps you are not waiting until you get permission before callinggetThumbnail()
.
– CommonsWare
2 days ago
@CommnsWare Please see the updated code above Edit 1
– Biswajit Das
2 days ago
|
show 6 more comments
up vote
0
down vote
Finally I am able to fix it calling from main class.
RxPermissions rxPermissions=new RxPermissions(this);
rxPermissions.request(Manifest.permission.READ_EXTERNAL_STORAGE)
.subscribe(granted -> {
if (granted) {
customDefineBtn.setOnClickListener(this);
LogUtil.e(LOG_TAG, "Granted external permission");
} else {
// Oups permission denied
}
});
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
My app needs below permissions
Note that your app cannot hold MOUNT_UNMOUNT_FILESYTEMS
unless it is signed by the firmware signing key or is installed on the privileged app partition (mostly for rooted devices).
Can we ask user all the permission in the main activity?
You do not have a choice, according to the documentation. According to those instructions, RxPermissions only works if you request the permissions from onCreate()
of your Activity
(or possibly onCreate()
of your Fragment
, though that part is unclear).
A sample code will help me
In addition to documentation, the RxPermissions GitHub repository has a sample app. Here is the v0.9.3 edition of that sample app.
@CommnsWare thanks for clarification. Last point as I said I can do easily from the activity. But I need to refer fragment. from helper class where I don't have fragment.
– Biswajit Das
2 days ago
@BiswajitDas: By the time you callgetThumbnail()
from anywhere, you need to ensure that you have your runtime permission. Then, you do not need anRxPermissions
instance ingetThumbnail()
. Your "helper" class appears to be a singleton; a singleton cannot and should not be attempting to request runtime permissions.
– CommonsWare
2 days ago
@CommnsWare friend inside main activity I am still getting the same error - Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/thumbnails from pid=25888, uid=10229 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
– Biswajit Das
2 days ago
@BiswajitDas: Perhaps you are not waiting until you get permission before callinggetThumbnail()
.
– CommonsWare
2 days ago
@CommnsWare Please see the updated code above Edit 1
– Biswajit Das
2 days ago
|
show 6 more comments
up vote
1
down vote
My app needs below permissions
Note that your app cannot hold MOUNT_UNMOUNT_FILESYTEMS
unless it is signed by the firmware signing key or is installed on the privileged app partition (mostly for rooted devices).
Can we ask user all the permission in the main activity?
You do not have a choice, according to the documentation. According to those instructions, RxPermissions only works if you request the permissions from onCreate()
of your Activity
(or possibly onCreate()
of your Fragment
, though that part is unclear).
A sample code will help me
In addition to documentation, the RxPermissions GitHub repository has a sample app. Here is the v0.9.3 edition of that sample app.
@CommnsWare thanks for clarification. Last point as I said I can do easily from the activity. But I need to refer fragment. from helper class where I don't have fragment.
– Biswajit Das
2 days ago
@BiswajitDas: By the time you callgetThumbnail()
from anywhere, you need to ensure that you have your runtime permission. Then, you do not need anRxPermissions
instance ingetThumbnail()
. Your "helper" class appears to be a singleton; a singleton cannot and should not be attempting to request runtime permissions.
– CommonsWare
2 days ago
@CommnsWare friend inside main activity I am still getting the same error - Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/thumbnails from pid=25888, uid=10229 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
– Biswajit Das
2 days ago
@BiswajitDas: Perhaps you are not waiting until you get permission before callinggetThumbnail()
.
– CommonsWare
2 days ago
@CommnsWare Please see the updated code above Edit 1
– Biswajit Das
2 days ago
|
show 6 more comments
up vote
1
down vote
up vote
1
down vote
My app needs below permissions
Note that your app cannot hold MOUNT_UNMOUNT_FILESYTEMS
unless it is signed by the firmware signing key or is installed on the privileged app partition (mostly for rooted devices).
Can we ask user all the permission in the main activity?
You do not have a choice, according to the documentation. According to those instructions, RxPermissions only works if you request the permissions from onCreate()
of your Activity
(or possibly onCreate()
of your Fragment
, though that part is unclear).
A sample code will help me
In addition to documentation, the RxPermissions GitHub repository has a sample app. Here is the v0.9.3 edition of that sample app.
My app needs below permissions
Note that your app cannot hold MOUNT_UNMOUNT_FILESYTEMS
unless it is signed by the firmware signing key or is installed on the privileged app partition (mostly for rooted devices).
Can we ask user all the permission in the main activity?
You do not have a choice, according to the documentation. According to those instructions, RxPermissions only works if you request the permissions from onCreate()
of your Activity
(or possibly onCreate()
of your Fragment
, though that part is unclear).
A sample code will help me
In addition to documentation, the RxPermissions GitHub repository has a sample app. Here is the v0.9.3 edition of that sample app.
answered 2 days ago
CommonsWare
755k13618431896
755k13618431896
@CommnsWare thanks for clarification. Last point as I said I can do easily from the activity. But I need to refer fragment. from helper class where I don't have fragment.
– Biswajit Das
2 days ago
@BiswajitDas: By the time you callgetThumbnail()
from anywhere, you need to ensure that you have your runtime permission. Then, you do not need anRxPermissions
instance ingetThumbnail()
. Your "helper" class appears to be a singleton; a singleton cannot and should not be attempting to request runtime permissions.
– CommonsWare
2 days ago
@CommnsWare friend inside main activity I am still getting the same error - Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/thumbnails from pid=25888, uid=10229 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
– Biswajit Das
2 days ago
@BiswajitDas: Perhaps you are not waiting until you get permission before callinggetThumbnail()
.
– CommonsWare
2 days ago
@CommnsWare Please see the updated code above Edit 1
– Biswajit Das
2 days ago
|
show 6 more comments
@CommnsWare thanks for clarification. Last point as I said I can do easily from the activity. But I need to refer fragment. from helper class where I don't have fragment.
– Biswajit Das
2 days ago
@BiswajitDas: By the time you callgetThumbnail()
from anywhere, you need to ensure that you have your runtime permission. Then, you do not need anRxPermissions
instance ingetThumbnail()
. Your "helper" class appears to be a singleton; a singleton cannot and should not be attempting to request runtime permissions.
– CommonsWare
2 days ago
@CommnsWare friend inside main activity I am still getting the same error - Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/thumbnails from pid=25888, uid=10229 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
– Biswajit Das
2 days ago
@BiswajitDas: Perhaps you are not waiting until you get permission before callinggetThumbnail()
.
– CommonsWare
2 days ago
@CommnsWare Please see the updated code above Edit 1
– Biswajit Das
2 days ago
@CommnsWare thanks for clarification. Last point as I said I can do easily from the activity. But I need to refer fragment. from helper class where I don't have fragment.
– Biswajit Das
2 days ago
@CommnsWare thanks for clarification. Last point as I said I can do easily from the activity. But I need to refer fragment. from helper class where I don't have fragment.
– Biswajit Das
2 days ago
@BiswajitDas: By the time you call
getThumbnail()
from anywhere, you need to ensure that you have your runtime permission. Then, you do not need an RxPermissions
instance in getThumbnail()
. Your "helper" class appears to be a singleton; a singleton cannot and should not be attempting to request runtime permissions.– CommonsWare
2 days ago
@BiswajitDas: By the time you call
getThumbnail()
from anywhere, you need to ensure that you have your runtime permission. Then, you do not need an RxPermissions
instance in getThumbnail()
. Your "helper" class appears to be a singleton; a singleton cannot and should not be attempting to request runtime permissions.– CommonsWare
2 days ago
@CommnsWare friend inside main activity I am still getting the same error - Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/thumbnails from pid=25888, uid=10229 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
– Biswajit Das
2 days ago
@CommnsWare friend inside main activity I am still getting the same error - Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/thumbnails from pid=25888, uid=10229 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
– Biswajit Das
2 days ago
@BiswajitDas: Perhaps you are not waiting until you get permission before calling
getThumbnail()
.– CommonsWare
2 days ago
@BiswajitDas: Perhaps you are not waiting until you get permission before calling
getThumbnail()
.– CommonsWare
2 days ago
@CommnsWare Please see the updated code above Edit 1
– Biswajit Das
2 days ago
@CommnsWare Please see the updated code above Edit 1
– Biswajit Das
2 days ago
|
show 6 more comments
up vote
0
down vote
Finally I am able to fix it calling from main class.
RxPermissions rxPermissions=new RxPermissions(this);
rxPermissions.request(Manifest.permission.READ_EXTERNAL_STORAGE)
.subscribe(granted -> {
if (granted) {
customDefineBtn.setOnClickListener(this);
LogUtil.e(LOG_TAG, "Granted external permission");
} else {
// Oups permission denied
}
});
add a comment |
up vote
0
down vote
Finally I am able to fix it calling from main class.
RxPermissions rxPermissions=new RxPermissions(this);
rxPermissions.request(Manifest.permission.READ_EXTERNAL_STORAGE)
.subscribe(granted -> {
if (granted) {
customDefineBtn.setOnClickListener(this);
LogUtil.e(LOG_TAG, "Granted external permission");
} else {
// Oups permission denied
}
});
add a comment |
up vote
0
down vote
up vote
0
down vote
Finally I am able to fix it calling from main class.
RxPermissions rxPermissions=new RxPermissions(this);
rxPermissions.request(Manifest.permission.READ_EXTERNAL_STORAGE)
.subscribe(granted -> {
if (granted) {
customDefineBtn.setOnClickListener(this);
LogUtil.e(LOG_TAG, "Granted external permission");
} else {
// Oups permission denied
}
});
Finally I am able to fix it calling from main class.
RxPermissions rxPermissions=new RxPermissions(this);
rxPermissions.request(Manifest.permission.READ_EXTERNAL_STORAGE)
.subscribe(granted -> {
if (granted) {
customDefineBtn.setOnClickListener(this);
LogUtil.e(LOG_TAG, "Granted external permission");
} else {
// Oups permission denied
}
});
answered yesterday
Biswajit Das
307417
307417
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238489%2fapi-26-runtime-permission-android-os-fileuriexposedexception%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
I'm assuming the library requires a
FragmentActivity
instance, which you are not supplying - yourmContext
is theApplication
looking at your naming of the parameter. Consider passing the correctContext
on the method calls inside your helper, not the constructor, as they should have a short lived scope you won't want to hold a reference to.– Mark Keen
2 days ago
Thanks @mark-keen. I am calling the helper class like this LocalAlbumImagePickerHelper.getInstance(LocalAlbumActivity.this). Do you want me to change here?
– Biswajit Das
2 days ago