disable ssl in curl on android, implement interactive permission for android 23+
This commit is contained in:
@@ -259,6 +259,15 @@ JNIEXPORT void JNICALL Java_com_omixlab_panopainter_MainActivity_pickFileCallbac
|
||||
}
|
||||
};
|
||||
}
|
||||
JNIEXPORT void JNICALL Java_com_omixlab_panopainter_MainActivity_pickExternalCallback(JNIEnv *env, jobject, jstring path)
|
||||
{
|
||||
const char* path_utf = env->GetStringUTFChars(path, nullptr);
|
||||
std::string file_path = path_utf; // create a copy
|
||||
env->ReleaseStringUTFChars(path, path_utf);
|
||||
|
||||
LOG("data_path %s", file_path.c_str());
|
||||
App::I.data_path = file_path;
|
||||
}
|
||||
}
|
||||
|
||||
void pick_file(android_app* mApplication, std::function<void(std::string)> callback)
|
||||
@@ -294,7 +303,6 @@ void pick_file(android_app* mApplication, std::function<void(std::string)> callb
|
||||
lJavaVM->DetachCurrentThread();
|
||||
}
|
||||
|
||||
|
||||
float get_display_density(android_app* mApplication)
|
||||
{
|
||||
// Attaches the current thread to the JVM.
|
||||
@@ -327,6 +335,42 @@ float get_display_density(android_app* mApplication)
|
||||
return density;
|
||||
}
|
||||
|
||||
std::string get_data_path(android_app* mApplication)
|
||||
{
|
||||
// Attaches the current thread to the JVM.
|
||||
jint lResult;
|
||||
jint lFlags = 0;
|
||||
|
||||
JavaVM* lJavaVM = mApplication->activity->vm;
|
||||
JNIEnv* lJNIEnv = mApplication->activity->env;
|
||||
|
||||
JavaVMAttachArgs lJavaVMAttachArgs;
|
||||
lJavaVMAttachArgs.version = JNI_VERSION_1_6;
|
||||
lJavaVMAttachArgs.name = "NativeThread";
|
||||
lJavaVMAttachArgs.group = NULL;
|
||||
|
||||
lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs);
|
||||
if (lResult == JNI_ERR)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
// Retrieves NativeActivity.
|
||||
jobject lNativeActivity = mApplication->activity->clazz;
|
||||
jclass ClassNativeActivity = lJNIEnv->GetObjectClass(lNativeActivity);
|
||||
|
||||
jmethodID MethodPickFile = lJNIEnv->GetMethodID(ClassNativeActivity, "getDataPath", "()Ljava/lang/String;");
|
||||
jstring path = (jstring)lJNIEnv->CallObjectMethod(lNativeActivity, MethodPickFile);
|
||||
|
||||
const char* path_utf = lJNIEnv->GetStringUTFChars(path, nullptr);
|
||||
std::string file_path = path_utf; // create a copy
|
||||
lJNIEnv->ReleaseStringUTFChars(path, path_utf);
|
||||
|
||||
// Finished with the JVM.
|
||||
lJavaVM->DetachCurrentThread();
|
||||
return file_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize an EGL context for the current display.
|
||||
*/
|
||||
@@ -594,7 +638,13 @@ static int engine_init_display(struct engine* engine) {
|
||||
Asset::m_am = engine->app->activity->assetManager;
|
||||
App::I.and_app = engine->app;
|
||||
App::I.and_engine = engine;
|
||||
App::I.data_path = "/sdcard/PanoPainter";// engine->app->activity->externalDataPath;
|
||||
|
||||
//std::string base_path = engine->app->activity->externalDataPath ?
|
||||
// engine->app->activity->externalDataPath : get_data_path(engine->app);
|
||||
if (App::I.data_path.empty() || App::I.data_path == ".")
|
||||
App::I.data_path = get_data_path(engine->app);
|
||||
LOG("data_path %s", App::I.data_path.c_str());
|
||||
|
||||
App::I.width = w;
|
||||
App::I.height = h;
|
||||
App::I.redraw = true;
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
package com.omixlab.panopainter;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.app.NativeActivity;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
public class MainActivity extends NativeActivity {
|
||||
@@ -13,7 +22,95 @@ public class MainActivity extends NativeActivity {
|
||||
System.loadLibrary("native-lib");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
checkPermissionReadStorage();
|
||||
}
|
||||
|
||||
public native void pickFileCallback(String path);
|
||||
public native void pickExternalCallback(String path);
|
||||
|
||||
public void setRootPath()
|
||||
{
|
||||
Log.v("MainActivity", "permission granted");
|
||||
File d = Environment.getExternalStorageDirectory();
|
||||
File pano_dir = new File(d, "PanoPainter");
|
||||
|
||||
if (!pano_dir.exists())
|
||||
{
|
||||
if (pano_dir.mkdirs())
|
||||
Log.v("MainActivity", "create path " + pano_dir.getAbsolutePath());
|
||||
else
|
||||
Log.v("MainActivity", "create path failed");
|
||||
|
||||
}
|
||||
pickExternalCallback(pano_dir.getAbsolutePath());
|
||||
}
|
||||
public void checkPermissionReadStorage(){
|
||||
Log.v("MainActivity", "permission checking");
|
||||
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) {
|
||||
setRootPath();
|
||||
} else {
|
||||
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
|
||||
// Should we show an explanation?
|
||||
/*if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||
|
||||
// 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.
|
||||
Log.v("MainActivity", "permission explanation");
|
||||
|
||||
|
||||
} else {
|
||||
*/
|
||||
// No explanation needed, we can request the permission.
|
||||
|
||||
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
|
||||
Log.v("MainActivity", "permission request");
|
||||
|
||||
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
|
||||
// app-defined int constant. The callback method gets the
|
||||
// result of the request.
|
||||
// }
|
||||
} else {
|
||||
Log.v("MainActivity", "permission already granted");
|
||||
setRootPath();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode,
|
||||
String permissions[], int[] grantResults) {
|
||||
switch (requestCode) {
|
||||
case 1: {
|
||||
//premission to read storage
|
||||
if (grantResults.length > 0
|
||||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
|
||||
// permission was granted, yay! Do the
|
||||
// contacts-related task you need to do.
|
||||
setRootPath();
|
||||
} else {
|
||||
Log.v("MainActivity", "permission denied");
|
||||
|
||||
// permission denied, boo! Disable the
|
||||
// functionality that depends on this permission.
|
||||
//Toast.makeText(this, "We Need permission Storage", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// other 'case' lines to check for other
|
||||
// permissions this app might request
|
||||
}
|
||||
}
|
||||
|
||||
public String getDataPath() {
|
||||
return getExternalFilesDir(null).getAbsolutePath();
|
||||
}
|
||||
|
||||
public float getDensity()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user