1

Unable to share file from personal to work profile in Profile owner on Android 6 and below.

I have written code to request and share file from personal profile to work profile in Profile owner application. I request for file from profile owner app to instance of same app in personal profile. I get the result in onActivityResult. I get the content Uri for the file which I process and save. The code works fine in android 7 and above but throws FileNotFound:Permission Denied exception on Android 6 and below.

 Intent resultIntent = new 
 Intent(RESULT);
            Uri uri = FileProviderHelper.getUriForFile(this, file);
            if (uri == null) {
                Logger.w(LOG_TAG, "Log file not found");


 LogCollectorActivity.this.setResult(RESULT_CANCELED, 
 resultIntent);
               Logger.e(LOG_TAG, " Unable to create Uri 
  from file");
                return;
            }
            resultIntent.setDataAndType(uri, 
getContentResolver().getType(uri));

resultIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            LogCollectorActivity.this.setResult(Activity.RESULT_OK, 
resultIntent);
finish();

And on the profile owner side I receive the result in onActivityResult

  @Override
protected void onActivityResult(int requestCode, int resultCode, 
@Nullable Intent data)
{
    if (requestCode == MIGRATE_LOGS && resultCode == 
 RESULT_OK) {
        migrateLogs(data);
    }
    updateStateAndFinish();
}


private void migrateLogs(Intent data)
   {
    if (data != null) {
        Uri dataUri = data.getData();
        if (dataUri != null) {
            try {
                ParcelFileDescriptor fileDescriptorParcel = 
           getContentResolver().openFileDescriptor(dataUri, "r");
       ...
 }

ParcelFileDescriptor fileDescriptorParcel = getContentResolver().openFileDescriptor(dataUri, "r"); Here I get FileNotFoundException: Permission denied.

I have tried to grant permission using context.grantUriPermission() but that doesn't work as well.

Mohammed Daoud
  • 202
  • 1
  • 10

0 Answers0