Fixed take picture option for old Android versions,

Changed "external-path" entry in paths.xml
pull/3/head
Olga Miller 2017-01-07 14:54:32 +01:00
rodzic 38423f76b9
commit 82710aa7e2
3 zmienionych plików z 23 dodań i 15 usunięć

Wyświetl plik

@ -32,7 +32,6 @@ import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.system.ErrnoException;
import android.system.OsConstants;
@ -58,7 +57,6 @@ public class MainActivity extends AppCompatActivity {
private TextOverlayTemplate mTextOverlayTemplate;
private CropView mCropView;
private Encoder mEncoder;
private File mFile;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -331,9 +329,10 @@ public class MainActivity extends AppCompatActivity {
dispatchTakePictureIntent();
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private boolean hasCamera() {
return getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN)
return getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
return getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA);
}
public void startEditTextActivity(@NonNull Label label) {
@ -345,9 +344,9 @@ public class MainActivity extends AppCompatActivity {
private void dispatchTakePictureIntent() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (intent.resolveActivity(getPackageManager()) != null) {
mFile = Utility.createImageFilePath();
if (mFile != null) {
Uri uri = FileProvider.getUriForFile(this, "om.sstvencoder", mFile);
Uri uri = Utility.createImageUri(this);
if (uri != null) {
mSettings.setImageUri(uri);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
}
@ -371,7 +370,7 @@ public class MainActivity extends AppCompatActivity {
break;
case REQUEST_IMAGE_CAPTURE:
if (resultCode == RESULT_OK) {
Uri uri = Uri.fromFile(mFile);
Uri uri = mSettings.getImageUri();
if (loadImage(uri, true))
addImageToGallery(uri);
}

Wyświetl plik

@ -16,12 +16,16 @@ limitations under the License.
package om.sstvencoder;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.content.FileProvider;
import java.io.File;
import java.text.SimpleDateFormat;
@ -87,18 +91,23 @@ public final class Utility {
return values;
}
static File createImageFilePath() {
File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
static Uri createImageUri(Context context) {
if (!isExternalStorageWritable())
return null;
return new File(dir, createFileName() + ".jpg");
File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File file = new File(dir, createFileName() + ".jpg");
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
// API level 24 and higher: FileUriExposedException
return Uri.fromFile(file); // file:// URI
// API level 15: Camera crash
return FileProvider.getUriForFile(context, "om.sstvencoder", file); // content:// URI
}
static File createWaveFilePath() {
// sdcard/Music
File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
if (!isExternalStorageWritable())
return null;
File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
return new File(dir, createFileName() + ".wav");
}

Wyświetl plik

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path
name="pictures"
path=""/>
name="media"
path="."/>
</paths>