Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<!-- Foreground services and network permissions -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down
60 changes: 8 additions & 52 deletions app/src/main/java/net/osmtracker/activity/TrackLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import android.net.Uri;

import android.os.Bundle;
import android.os.Environment;
import android.os.StrictMode;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
Expand All @@ -53,6 +52,7 @@
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
Expand All @@ -75,7 +75,6 @@ public class TrackLogger extends Activity {
private static final String TAG = TrackLogger.class.getSimpleName();

final private int RC_STORAGE_AUDIO_PERMISSIONS = 1;
final private int RC_STORAGE_CAMERA_PERMISSIONS = 2;

/**
* Request code for callback after the camera application had taken a
Expand Down Expand Up @@ -526,34 +525,7 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
case KeyEvent.KEYCODE_CAMERA:
Log.d(TAG, "click on camera button");
if (gpsLogger.isTracking()) {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "camera permission isn't granted, will request");
// Should we show an explanation?
if ( (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.CAMERA)) ) {

// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
// TODO: explain why we need permission.
Log.w(TAG, "we should explain why we need write and record audio permission");

} else {

// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{
Manifest.permission.CAMERA},
RC_STORAGE_CAMERA_PERMISSIONS);
break;
}

} else {
requestStillImage();
//return true;
}

requestStillImage();
}
break;
case KeyEvent.KEYCODE_DPAD_CENTER:
Expand Down Expand Up @@ -800,8 +772,13 @@ public long getCurrentTrackId() {
private void startCamera(File imageFile) {
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());

Uri imageUriContent = FileProvider.getUriForFile(this,
DataHelper.FILE_PROVIDER_AUTHORITY, imageFile);

Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
cameraIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUriContent);
startActivityForResult(cameraIntent, REQCODE_IMAGE_CAPTURE);
}

Expand Down Expand Up @@ -837,27 +814,6 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
}
return;
}

case RC_STORAGE_CAMERA_PERMISSIONS: {
Log.d(TAG, "camera case");
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 1) {
// TODO: fix permission management
//&& grantResults[0] == PackageManager.PERMISSION_GRANTED
//&& grantResults[1] == PackageManager.PERMISSION_GRANTED) {

// permission was granted, yay!
requestStillImage();

} else {

// permission denied, boo! Disable the
// functionality that depends on this permission.
//TODO: add an informative message.
Log.v(TAG, "Camera permission is denied.");
}
return;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

import net.osmtracker.activity.TrackLogger;

import android.Manifest;
import android.content.pm.PackageManager;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import android.view.View;
import android.view.View.OnClickListener;

Expand All @@ -22,68 +17,13 @@ public class StillImageOnClickListener implements OnClickListener {
* Parent activity
*/
TrackLogger activity;

final private int RC_STORAGE_CAMERA_PERMISSIONS = 2;

public StillImageOnClickListener(TrackLogger parent) {
activity = parent;
}

@Override
public void onClick(View v) {
if (ContextCompat.checkSelfPermission(activity,
Manifest.permission.WRITE_EXTERNAL_STORAGE) + ContextCompat.checkSelfPermission(activity,
Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {

// Should we show an explanation?
if ( (ActivityCompat.shouldShowRequestPermissionRationale(activity,
Manifest.permission.WRITE_EXTERNAL_STORAGE))
|| (ActivityCompat.shouldShowRequestPermissionRationale(activity,
Manifest.permission.CAMERA)) ) {

// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
// TODO: explain why we need permission.
//"we should explain why we need write and record audio permission"

} else {

// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(activity,
new String[]{
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA},
RC_STORAGE_CAMERA_PERMISSIONS);
}

} else {
activity.requestStillImage();
}

activity.requestStillImage();
}

public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case RC_STORAGE_CAMERA_PERMISSIONS: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length == 2
&& grantResults[0] == PackageManager.PERMISSION_GRANTED
&& grantResults[1] == PackageManager.PERMISSION_GRANTED) {

// permission was granted, yay!
activity.requestStillImage();

} else {

// permission denied, boo! Disable the
// functionality that depends on this permission.
//TODO: add an informative message.
}
return;
}
}
}

}