mirror of
https://github.com/vanitasvitae/Spherical
synced 2024-11-24 21:32:07 +01:00
Ask for permission to access external storage
This commit is contained in:
parent
09241253c8
commit
7ae568c3b0
3 changed files with 45 additions and 4 deletions
|
@ -5,7 +5,7 @@ android {
|
|||
buildToolsVersion "25.0.3"
|
||||
defaultConfig {
|
||||
applicationId "de.trac.spherical"
|
||||
minSdkVersion 15
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 25
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
package de.trac.spherical;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.AppBarLayout;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
|
@ -38,11 +41,15 @@ public class MainActivity extends AppCompatActivity {
|
|||
public static final String MIME_PHOTO_SPHERE = "application/vnd.google.panorama360+jpg";
|
||||
public static final String MIME_IMAGE = "image/*";
|
||||
|
||||
private static final int PERMISSION_REQUEST_READ_EXTERNAL_STORAGE = 387;
|
||||
|
||||
private SphereSurfaceView surfaceView;
|
||||
private Renderer renderer;
|
||||
private FloatingActionButton fab;
|
||||
private Toolbar toolbar;
|
||||
|
||||
private Intent cachedIntent;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -92,11 +99,14 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
|
||||
Intent intent = getIntent();
|
||||
handleIntent(getIntent());
|
||||
}
|
||||
|
||||
private void handleIntent(Intent intent) {
|
||||
switch (intent.getAction()) {
|
||||
//Image was sent into the app
|
||||
case Intent.ACTION_SEND:
|
||||
handleSentImageIntent(intent);
|
||||
checkPermissionAndHandleSentImage(intent);
|
||||
break;
|
||||
|
||||
//App was launched via launcher icon
|
||||
|
@ -106,6 +116,36 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
|
||||
private void checkPermissionAndHandleSentImage(Intent intent) {
|
||||
int status = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||
if (status == PackageManager.PERMISSION_GRANTED) {
|
||||
handleSentImageIntent(intent);
|
||||
}
|
||||
|
||||
// Cache intent and request permission
|
||||
this.cachedIntent = intent;
|
||||
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
|
||||
PERMISSION_REQUEST_READ_EXTERNAL_STORAGE);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode,
|
||||
String permissions[], int[] grantResults) {
|
||||
switch (requestCode) {
|
||||
case PERMISSION_REQUEST_READ_EXTERNAL_STORAGE: {
|
||||
// If request is cancelled, the result arrays are empty.
|
||||
if (grantResults.length > 0
|
||||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
handleSentImageIntent(cachedIntent);
|
||||
} else {
|
||||
Toast.makeText(this, R.string.missing_permission, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void displayUI(boolean display) {
|
||||
if (display) {
|
||||
fab.show();
|
||||
|
|
|
@ -6,4 +6,5 @@
|
|||
<string name="wow">WOW! SUCH 3D!!!</string>
|
||||
<string name="menu_force_sphere">Show as Sphere</string>
|
||||
<string name="not_yet_implemented">Not yet implemented!</string>
|
||||
<string name="missing_permission">Cannot display photo: Missing permissions to access external storage.</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue