Skip to content

Commit

Permalink
Merge pull request #8575 from remibettan/android-fixing-record-over-a…
Browse files Browse the repository at this point in the history
…ndroid11

Android fixing record over android11
  • Loading branch information
ev-mp authored Mar 14, 2021
2 parents 6e01478 + 4218873 commit 1491ad6
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Thread mStreaming = new Thread() {
@Override
public void run() {
String filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + mUri.getPath().split(":")[1];
String filePath = getExternalFilesDir(null).getAbsolutePath() + "/" + mUri.getPath().split(":")[1];
try(Colorizer colorizer = new Colorizer()) {
try (Config config = new Config()) {
config.enableDeviceFromFile(filePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ protected void onPause() {
}

private String getFilePath(){
File folder = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "rs_bags");
File folder = new File(getExternalFilesDir(null).getAbsolutePath() + File.separator + "rs_bags");
folder.mkdir();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
String currentDateAndTime = sdf.format(new Date());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected void onResume() {

TextView message = findViewById(R.id.list_view_title);

File folder = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + mFolder);
File folder = new File(getExternalFilesDir(null).getAbsolutePath() + File.separator + mFolder);
if(!folder.exists()) {
message.setText("No RealSense files found");
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.intel.realsense.camera;

import android.os.Environment;
import android.content.Context;
import android.os.Handler;
import android.util.Log;

Expand All @@ -22,17 +22,13 @@ public static final void runOnUiThread(Runnable action) {
}
}

public static boolean isExternalStorageWritable() {
return Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED;
public static String getExternalStorageDir(Context context) {
return context.getExternalFilesDir(null).getAbsolutePath();
}

public static String getExternalStorageDir() {
return Environment.getExternalStorageDirectory().getAbsolutePath();
}

public static void saveFileToExternalDir(final String fileName, byte[] data) {
public static void saveFileToExternalDir(Context context, final String fileName, byte[] data) {
try {
File file = new File(getExternalStorageDir() + File.separator + fileName);
File file = new File(context.getExternalFilesDir(null) + File.separator + fileName);
FileOutputStream fos = new FileOutputStream(file);
fos.write(data);
Log.i(TAG, "saveFileToExternalDir: file " + fileName + " saved successfully");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
Expand Down Expand Up @@ -102,10 +101,10 @@ protected void onPause() {
}

private String getFilePath(){
File rsFolder = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +
File rsFolder = new File(getExternalFilesDir(null).getAbsolutePath() +
File.separator + getString(R.string.realsense_folder));
rsFolder.mkdir();
File folder = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +
File folder = new File(getExternalFilesDir(null).getAbsolutePath() +
File.separator + getString(R.string.realsense_folder) + File.separator + "video");
folder.mkdir();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected void onCreate(Bundle savedInstanceState) {
mContext = this;

// Advanced features are enabled if xml files exists in the device.
String advancedFeaturesPath = FileUtilities.getExternalStorageDir() +
String advancedFeaturesPath = FileUtilities.getExternalStorageDir(mContext) +
File.separator +
getString(R.string.realsense_folder) +
File.separator +
Expand Down Expand Up @@ -205,7 +205,7 @@ public void onItemClick(AdapterView<?> parent, final View view,
break;
}
case INDEX_CREATE_FLASH_BACKUP: {
new FlashBackupTask(device).execute();
new FlashBackupTask(device, mContext).execute();
break;
}
default:
Expand All @@ -220,15 +220,17 @@ private class FlashBackupTask extends AsyncTask<Void, Void, Void> {
private ProgressDialog mProgressDialog;
private Device mDevice;
String mBackupFileName = "fwdump.bin";
private Context mContext;

public FlashBackupTask(Device mDevice) {
public FlashBackupTask(Device mDevice, Context context) {
this.mDevice = mDevice;
this.mContext = context;
}

@Override
protected Void doInBackground(Void... voids) {
try(final Updatable upd = mDevice.as(Extension.UPDATABLE)){
FileUtilities.saveFileToExternalDir(mBackupFileName, upd.createFlashBackup());
FileUtilities.saveFileToExternalDir(mContext, mBackupFileName, upd.createFlashBackup());
return null;
}
}
Expand All @@ -255,7 +257,7 @@ protected void onPostExecute(Void aVoid) {
public void run() {
new AlertDialog.Builder(mContext)
.setTitle("Firmware Backup Success")
.setMessage("Saved into: " + FileUtilities.getExternalStorageDir() + File.separator + mBackupFileName)
.setMessage("Saved into: " + FileUtilities.getExternalStorageDir(mContext) + File.separator + mBackupFileName)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public synchronized void start() throws Exception {
mHandler.post(mStreaming);
Log.d(TAG, "streaming started successfully");
} catch (Exception e) {
Log.e(TAG, "failed to start streaming");
Log.e(TAG, "failed to start streaming: " + e.getMessage());
mPipeline.close();
throw e;
}
Expand Down

0 comments on commit 1491ad6

Please sign in to comment.