onActivityForResult data is null - android

Recently, I updated a project with android 7.0 and upper.
I figured out the provider problem.
When I take photo and use onActivityForResult to resize the image or show it. I find the data is null. I wonder why? I have tried several ways to get Uri.
But the data is null.
//A button click to call this.
Uri tempUri;
private void takePhoto() {
if (isSdcardExisting()) {
//create a file.
File file = new File(getExternalFilesAbsolutePath(this),HERO_IMAGE);
if(file.exists()){
try {
file.delete();
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
//use a class to deal uri problem android 7.0 problem.
Uri uri = FileProvider7.getUriForFile(this,file);
Intent cameraIntent = new Intent("android.media.action.IMAGE_CAPTURE");
//put some keys to intent
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
cameraIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
/*
* grant uri
*
* the temp sulution :
* tempUri = uri;
*/
FileProvider7.grantUriPermission(this,cameraIntent,uri);
startActivityForResult(cameraIntent, CODE_TAKE_PHOTO);
} else {
Toast.makeText(this, "请插入SD卡", Toast.LENGTH_LONG)
.show();
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
if(resultCode != RESULT_OK){
return;
}else{
switch (requestCode){
case CODE_TAKE_PHOTO:
/**
* the requestCode and resultCode is right,but the data is null
* I wander how to use this.
*
* the temp solution is to define a Uri obejct to store the uri.
*
* if(tempUri != null)
* resize(tempUri);
*/
Log.d(TAG, "onActivityResult: data ---> " + data);
if(data != null){
Bundle bundle = data.getExtras();
Log.d(TAG, "onActivityResult: bundle ---> " + bundle);
if(bundle != null){
Uri resizeUri = bundle.getParcelable(MediaStore.EXTRA_OUTPUT);
Log.d(TAG, "onActivityResult: resizeUri ---> " + resizeUri);
String imageType = bundle.getString("outputFormat");
Log.d(TAG, "onActivityResult: imageType ---> " + imageType);
Uri uri = data.getData();
Log.d(TAG, "onActivityResult: getData ---> " + uri);
resize(resizeUri);
}
}
break;
case CODE_SHOW_IMAGE:
break;
}
}
super.onActivityResult(requestCode, resultCode, data);
}
I found a solution that the activity needs to add action in manifest activity intent filter.But it doesn't seems to work.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rambopan.demotryusercamera">
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="com.android.camera.action.CROP"/>
<action android:name="android.media.action.IMAGE_CAPTURE"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
</application>
</manifest>
The log.The uri is ok,the data is null.(Android 5.0)
06-12 15:26:11.063 368-368/com.rambopan.demotryusercamera D/XADAX.FileProvider7: getUriForFile: ---> file:///storage/emulated/0/Android/data/com.rambopan.demotryusercamera/files/hero
06-12 15:26:32.624 368-368/com.rambopan.demotryusercamera D/XADAX.MainActivity: onActivityResult: data ---> null

You can get the image from the uri variable that you are sending in cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

Related

Camera intent opens camera but does not show tick and cross page when click image

I used similar code in different apps but still this time I am getting a problem. upon calling startActivityForResult(CamIntent, Integer.parseInt(code)); camera open but when I click image nothing happens it keeps clicking the image but does not show image page with tick and cross icons.
In Manifest File
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths"></meta-data>
</provider>
#xml/file_paths
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="." />
</paths>
Code in Activity
public void ClickImageFromCamera(String code) {
Intent CamIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File destination = new File(Environment.getExternalStorageDirectory(), System.currentTimeMillis() + ".jpg");
Log.e("img fromCam", String.valueOf(destination));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
uri = FileProvider.getUriForFile(Objects.requireNonNull(getApplicationContext()),
BuildConfig.APPLICATION_ID + ".fileprovider", destination);
Log.e("img uri", String.valueOf(uri));
CamIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
} else {
uri = Uri.fromFile(destination);
CamIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
}
CamIntent.putExtra("return-data", true);
startActivityForResult(CamIntent, Integer.parseInt(code));
}
Log
D/CompatibilityChangeReporter: Compat change id reported: 147798919; UID 10625; state: DISABLED
D/OpenGLRenderer: endAllActiveAnimators on 0x76e3d22fc0 (AlertController$RecycleListView) with handle 0x7603cc4890
E/img fromCam: /storage/emulated/0/1611230389449.jpg
E/img uri: content://com.example.aps.fileprovider/external_files/1611230389449.jpg
E/Request code: 0 (when I click back)
E/ResultCode: 0
private void openCameraImagePickerIntent() {
int FRONT_CAMERA = 0;
int BACK_CAMERA = 1;
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra("android.intent.extras.CAMERA_FACING",BACK_CAMERA);
startActivityForResult(intent, 14596);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 14596 && resultCode == RESULT_OK) {
Bitmap imageBitmap = (Bitmap) data.getExtras().get("data");
//Save imageBitmap in storage
}
}

Cordova Android clicking input type=file brings up system file browser, not camera options

Problem
In Cordova Android when clicking on an html type="file" input a system file picker appears instead of camera options.
What is expected to happen?
If I perform the same action in the system browser I get the expected dialog:
Version information
"cordova-android": "^8.0.0",
"cordova-plugin-camera": "^4.1.0"
cordova-cli 9.0.0
Full test case repo here
This is my first Android Cordova application, am I missing a certain plugin? I don't remember being asked for permission to use the camera at any stage so I wonder if I'm missing something in the config.xml linked above?
You need to set the capture and accept attributes like below:
<input type="file" capture="camera" accept="image/*" />
EDIT
Also, make sure your platforms/android/AndroidManifest.xml includes the following elements:
<application android:allowBackup="false" android:hardwareAccelerated="true" android:icon="#mipmap/icon" android:label="#string/app_name">
<provider android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true" android:name="android.support.v4.content.FileProvider">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="#xml/file_paths" />
</provider>
<provider android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true" android:name="org.apache.cordova.camera.FileProvider">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="#xml/camera_provider_paths" />
</provider>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
If they don't already exist, create file platforms/android/res/xml/file_paths.xml containing:
<!-- file_paths.xml -->
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<cache-path name="photos" path="photos/" />
</paths>
and file platforms/android/res/xml/camera_provider_paths.xml:
<!-- camera_provider_paths.xml -->
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
If that still does not seem to do the trick, you may additionally need to add/modify the SystemWebChromeClient.java file in the platforms/android/CordovaLib/src/org/apache/cordova/engine directory to include the following:
#TargetApi(Build.VERSION_CODES.LOLLIPOP)
#Override
public boolean onShowFileChooser(WebView webView, final ValueCallback<Uri[]> filePathsCallback, final WebChromeClient.FileChooserParams fileChooserParams) {
// Image from file intent
boolean multiple = fileChooserParams.getMode() == WebChromeClient.FileChooserParams.MODE_OPEN_MULTIPLE;
String type = "*/*";
if (fileChooserParams.getAcceptTypes() != null && fileChooserParams.getAcceptTypes().length > 0) {
type = fileChooserParams.getAcceptTypes()[0];
}
Intent fileIntent = new Intent(Intent.ACTION_GET_CONTENT);
fileIntent.addCategory(Intent.CATEGORY_OPENABLE);
fileIntent.setTypeAndNormalize(type);
fileIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, multiple);
// Image from camera intent
Uri tempUri = null;
Intent captureIntent = null;
if (fileChooserParams.isCaptureEnabled()) {
captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Context context = parentEngine.getView().getContext();
if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA) && captureIntent.resolveActivity(context.getPackageManager()) != null) {
try {
File tempFile = createTempFile(context);
Log.d(LOG_TAG, "Temporary photo capture file: " + tempFile);
tempUri = createUriForFile(context, tempFile);
Log.d(LOG_TAG, "Temporary photo capture URI: " + tempUri);
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, tempUri);
} catch (IOException e) {
Log.e(LOG_TAG, "Unable to create temporary file for photo capture", e);
captureIntent = null;
}
} else {
Log.w(LOG_TAG, "Device does not support photo capture");
captureIntent = null;
}
}
final Uri captureUri = tempUri;
// Chooser intent
Intent chooserIntent = Intent.createChooser(fileIntent, null);
if (captureIntent != null) {
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { captureIntent });
}
try {
Log.i(LOG_TAG, "Starting intent for file chooser");
parentEngine.cordova.startActivityForResult(new CordovaPlugin() {
#Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
// Handle result
Uri[] result = null;
if (resultCode == Activity.RESULT_OK) {
List<Uri> uris = new ArrayList<Uri>();
if (intent == null && captureUri != null) { // camera
Log.v(LOG_TAG, "Adding camera capture: " + captureUri);
uris.add(captureUri);
} else if (intent.getClipData() != null) { // multiple files
ClipData clipData = intent.getClipData();
int count = clipData.getItemCount();
for (int i = 0; i < count; i++) {
Uri uri = clipData.getItemAt(i).getUri();
Log.v(LOG_TAG, "Adding file (multiple): " + uri);
if (uri != null) {
uris.add(uri);
}
}
} else if (intent.getData() != null) { // single file
Log.v(LOG_TAG, "Adding file (single): " + intent.getData());
uris.add(intent.getData());
}
if (!uris.isEmpty()) {
Log.d(LOG_TAG, "Receive file chooser URL: " + uris.toString());
result = uris.toArray(new Uri[uris.size()]);
}
}
filePathsCallback.onReceiveValue(result);
}
}, chooserIntent, FILECHOOSER_RESULTCODE);
} catch (ActivityNotFoundException e) {
Log.w("No activity found to handle file chooser intent.", e);
filePathsCallback.onReceiveValue(null);
}
return true;
}

ACTION_IMAGE_CAPTURE onActivityResult has empty intent with empty data

After reading this documentation https://developer.android.com/training/camera/photobasics I want to take a photo and to store the uri of the photo into a given variable. The problem is that I'm storing the variable name and the uri into the intent with takePictureIntent.putExtra(Constants.INTENT_EXTRA_VARNAME, variable) and takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI), but in onActivityResult the intent data is empty, and neither the variable and the uri stored are empty. I need to know the uri and the variable. What am I doing wrong?
I need to pass the information as intent data because the class which is firing the action of displaying the camera is differente from the activity class.
class with the action:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra(Constants.INTENT_EXTRA_VARNAME, variable);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(SectionManager.getInstance().getCurrentActivity().getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
ex.printStackTrace();
}
// Continue only if the File was successfully created
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(SectionManager.getInstance().getCurrentActivity(), SectionManager.getInstance().getCurrentActivity().getPackageName(), photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
SectionManager.getInstance().getCurrentActivity().startActivityForResult(takePictureIntent, Constants.REQUEST_IMAGE_CAPTURE);
}
}
my activity which receives the result:
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if( requestCode == Constants.REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK){
String varName;
String path;
if(intent != null) {
varName = intent.getStringExtra(Constants.INTENT_EXTRA_VARNAME);
path = Util.getRealPathFromURI(SectionManager.getInstance().getCurrentActivity(), intent.getData());
Log.d(DEBUG_TAG, "onActivityResult-> varName: "+varName+" path: "+path);
if (varName != null && path != null) {
VariableManager.put(varName, path);
}
}
}
}
manifest, permission write_external_storage and this code:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths"></meta-data>
</provider>
file_paths.xml file:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="my_images" path="/" />
</paths>
You already have photoURI which you send with MediaStore.EXTRA_OUTPUT so You can simply use it . Save photoURI as globally and directly use it . See if RESULT_OK is emitted then it means picture was clicked and it will be saved at the EXTRA_OUTPUT location.
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if( requestCode == Constants.REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK){
// USe photoURi here
}
}
You can not expect some custom key which is Constants.INTENT_EXTRA_VARNAME will be return with System camera Intent. I do not have any knowledge of such thing.
If you specified MediaStore.EXTRA_OUTPUT the image taken will be written to that path, and no data will given to onActivityResult so you need to persist the file path.
PS : You can save it globally and also make sure you should persist it during onSaveInstanceState().

Launching camera and creating a name for the picture is returning null Intent to onActivityResult

My problem is in this line:
pictureUri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".provider", createImageFile());
when i comment it the camera does not return null intent to onActivityResult but when I uncomment it, it sends null to Intent data,but its saving the file with the name i specified.
Here is the code:
Start Camera:
private void invokeCamera() {
// get a file reference
Uri pictureUri;
pictureUri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".provider", createImageFile());
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// tell the camera where to save the image.
intent.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri);
// tell the camera to request WRITE permission.
intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
}
Create File:
private File createImageFile() {
File imageFile;
// the public picture director
File picturesDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
String IMGname = Ti.getText().toString() + IMGCounter;
// put together the directory and the timestamp to make a unique image location.
imageFile = new File(picturesDirectory, IMGname + ".jpg");
Toast.makeText(this, IMGname + ".jpg", Toast.LENGTH_LONG).show();
return imageFile;
}
onActivityResult code:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK && data != null){
if(requestCode == REQUEST_IMAGE_CAPTURE) {
Toast.makeText(this, "Reached REq", Toast.LENGTH_SHORT).show();
// AddImgToView(data);
}else if(requestCode == IMAGE_GALLERY_REQUEST){
AddImgToView(data);
}
}else{
Toast.makeText(this, "Op 2"+data, Toast.LENGTH_SHORT).show();
}
}
Manifest Code:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<!--Required Permissions-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<provider
android:authorities="company.com.retrofit.provider"
android:name="android.support.v4.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="#xml/file_paths"/>
</provider>
<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=".InsertData"></activity>
</application>
Check for writing to external storage permission , implement dynamic permission model, I see nothing wrong in the code otherwise
I found out that the default Android camera sends data when you are sending a thumbnail, but when you use EXTRA_OUTPUT it sends null and I have to use the URI I specified.

Auto download and install apk in android O

I'm trying to implement auto download and install apk in my application using file provider. For android version less than Oreo it works fine but getting problem while running app on device with android 8.0 and above. It works fine till Nougat, but doesn't works with Oreo. Downloading apk from server working fine but fails to install new apk.
Here is my code.
File file, folder;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Utility.checkPermissionCamera(Main2Activity.this);
Utility.checkPermissionInstall(Main2Activity.this);
String fileName = "AutoDownloadApplication.apk";
folder = new File(getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).toString());
Logger.e("FOLDER", " " + folder);
file = new File(folder.getAbsolutePath(), fileName);
Log.e("File ", "" + file);
final Uri uri = FileProvider.getUriForFile(Main2Activity.this, BuildConfig.APPLICATION_ID + ".provider", file);
Logger.e("Check URI ", "" + uri);
if (Utility.checkPermissionCamera(Main2Activity.this)) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(StaticConstant.DOWNLOADAPK));
request.setDescription("Downloading New Apk");
request.setTitle(Main2Activity.this.getString(R.string.app_name));
//set destination
request.setDestinationInExternalFilesDir(Main2Activity.this, BuildConfig.APPLICATION_ID + ".provider", fileName);
// get download service and enqueue file
final DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
final long downloadId = manager.enqueue(request);
//set BroadcastReceiver to install app when .apk is downloaded
BroadcastReceiver onComplete = new BroadcastReceiver() {
public void onReceive(Context ctxt, Intent intent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
intent.setData(uri);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
} else {
Intent install = new Intent(Intent.ACTION_VIEW);
install.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
install.setDataAndType(uri,
manager.getMimeTypeForDownloadedFile(downloadId));
startActivity(install);
}
unregisterReceiver(this);
}
};
//register receiver for when .apk download is compete
registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}
}
Manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="MyPackageName">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<permission
android:name="android.permission.REQUEST_INSTALL_PACKAGES"
android:protectionLevel="normal" />
<uses-permission
android:name="android.permission.REQUEST_DELETE_PACKAGES"
tools:ignore="ProtectedPermissions" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="MyPackageName.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
</application>
Here is the file_paths xml:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="Download" path="Android/data/MyPackageName/files/Download"/>
</paths>
Please add the <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/> permission in Manifest.xml first.
We should check the result of getPackageManager().canRequestPackageInstalls() if the SDK version is equal or large than 26.
The code is below:
private void checkIsAndroidO() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
boolean result = getPackageManager().canRequestPackageInstalls();
if (result) {
installApk();
} else {
// request the permission
ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.REQUEST_INSTALL_PACKAGES}, INSTALL_PACKAGES_REQUESTCODE);
}
} else {
installApk();
}
}
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case INSTALL_PACKAGES_REQUESTCODE:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
installApk();
} else {
Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES);
startActivityForResult(intent, GET_UNKNOWN_APP_SOURCES);
}
break;
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case GET_UNKNOWN_APP_SOURCES:
checkIsAndroidO();
break;
default:
break;
}
}
I hope it will help you.
You can read more about FileProvider implementation in details how it works from below article:
https://inthecheesefactory.com/blog/how-to-share-access-to-file-with-fileprovider-on-android-nougat/en
The soluciton of JohnWatsonDev Worked perfectly!
Just one thing, to call your app directly, is just put:
intent.setData(Uri.parse("package:" + getPackageName()));
Before call
startActivityForResult(intent, GET_UNKNOWN_APP_SOURCES);

Categories

Resources