diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml
index df817b82..cfc9d55b 100755
--- a/android/AndroidManifest.xml
+++ b/android/AndroidManifest.xml
@@ -1,26 +1,56 @@
-
-
-
-
-
-
-
-
-
-
-
+ package="org.purplei2p.i2pd"
+ android:installLocation="auto"
+ android:versionCode="1"
+ android:versionName="2.18.0">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
-
+
+
\ No newline at end of file
diff --git a/android/build.gradle b/android/build.gradle
index c270e809..4fe17d88 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -17,11 +17,6 @@ repositories {
}
}
-dependencies {
- compile 'com.android.support:support-v4:25.3.1'
- compile 'com.android.support:design:25.3.1'
-}
-
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
@@ -33,6 +28,7 @@ android {
versionName "2.18.0"
ndk {
abiFilters 'armeabi-v7a'
+ //abiFilters 'x86'
}
}
sourceSets {
@@ -65,3 +61,4 @@ android {
}
}
+
diff --git a/android/res/layout/activity_perms_explanation.xml b/android/res/layout/activity_perms_explanation.xml
new file mode 100644
index 00000000..1c9cce82
--- /dev/null
+++ b/android/res/layout/activity_perms_explanation.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml
index 1421b261..a0cc264c 100755
--- a/android/res/values/strings.xml
+++ b/android/res/values/strings.xml
@@ -14,4 +14,5 @@
i2pd: graceful shutdown in progress
i2pd has stopped
remaining
+ Prompt
diff --git a/android/src/org/purplei2p/i2pd/I2PDActivity.java b/android/src/org/purplei2p/i2pd/I2PDActivity.java
index d829bd06..99672eb7 100755
--- a/android/src/org/purplei2p/i2pd/I2PDActivity.java
+++ b/android/src/org/purplei2p/i2pd/I2PDActivity.java
@@ -12,14 +12,13 @@ import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
-import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
-public class I2PDActivity extends AppCompatActivity {
+public class I2PDActivity extends Activity {
private static final String TAG = "i2pdActvt";
public static final int GRACEFUL_DELAY_MILLIS = 10 * 60 * 1000;
diff --git a/android/src/org/purplei2p/i2pd/I2PDPermsAskerActivity.java b/android/src/org/purplei2p/i2pd/I2PDPermsAskerActivity.java
index 5462ab24..3e364949 100644
--- a/android/src/org/purplei2p/i2pd/I2PDPermsAskerActivity.java
+++ b/android/src/org/purplei2p/i2pd/I2PDPermsAskerActivity.java
@@ -5,29 +5,32 @@ import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
-import android.support.v4.app.ActivityCompat;
-import android.support.design.widget.Snackbar;
-import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
+import java.lang.reflect.Method;
+
//dangerous perms, per https://developer.android.com/guide/topics/permissions/normal-permissions.html :
//android.permission.WRITE_EXTERNAL_STORAGE
-public class I2PDPermsAskerActivity extends AppCompatActivity {
+public class I2PDPermsAskerActivity extends Activity {
private static final int PERMISSION_WRITE_EXTERNAL_STORAGE = 0;
- private View mLayout;
private Button button_request_write_ext_storage_perms;
private TextView textview_retry;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ //if less than Android 6, no runtime perms req system present
+ if (android.os.Build.VERSION.SDK_INT < 23) {
+ startMainActivity();
+ return;
+ }
+
setContentView(R.layout.activity_perms_asker);
- mLayout = findViewById(R.id.main_layout);
button_request_write_ext_storage_perms = (Button) findViewById(R.id.button_request_write_ext_storage_perms);
textview_retry = (TextView) findViewById(R.id.textview_retry);
@@ -45,41 +48,55 @@ public class I2PDPermsAskerActivity extends AppCompatActivity {
textview_retry.setVisibility(TextView.GONE);
button_request_write_ext_storage_perms.setVisibility(Button.GONE);
- // Here, thisActivity is the current activity
- if (ActivityCompat.checkSelfPermission(this,
- Manifest.permission.WRITE_EXTERNAL_STORAGE)
- != PackageManager.PERMISSION_GRANTED) {
+ Method methodCheckPermission;
+ Method method_shouldShowRequestPermissionRationale;
+ Method method_requestPermissions;
+ try {
+ methodCheckPermission = getClass().getMethod("checkSelfPermission", String.class);
+ method_shouldShowRequestPermissionRationale =
+ getClass().getMethod("shouldShowRequestPermissionRationale", String.class);
+ method_requestPermissions =
+ getClass().getMethod("requestPermissions", String[].class, int.class);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(e);
+ }
+ Integer resultObj;
+ try {
+ resultObj = (Integer) methodCheckPermission.invoke(
+ this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+
+ if (resultObj != PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
- if (ActivityCompat.shouldShowRequestPermissionRationale(this,
- Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
+ Boolean aBoolean;
+ try {
+ aBoolean = (Boolean) method_shouldShowRequestPermissionRationale.invoke(this,
+ Manifest.permission.WRITE_EXTERNAL_STORAGE);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ if (aBoolean) {
// Show an explanation 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.
- Snackbar.make(mLayout, "SD card write access is required to write the keys and other files to the I2PD folder on SD card.",
- Snackbar.LENGTH_INDEFINITE).setAction("OK", new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- // Request the permission
- ActivityCompat.requestPermissions(I2PDPermsAskerActivity.this,
- new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
- PERMISSION_WRITE_EXTERNAL_STORAGE);
- }
- }).show();
+ showExplanation();
} else {
// No explanation needed, we can request the permission.
- ActivityCompat.requestPermissions(this,
- new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
- PERMISSION_WRITE_EXTERNAL_STORAGE);
-
- // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
- // app-defined int constant. The callback method gets the
- // result of the request.
+ try {
+ method_requestPermissions.invoke(this,
+ new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
+ PERMISSION_WRITE_EXTERNAL_STORAGE);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
}
} else startMainActivity();
}
@@ -118,4 +135,37 @@ public class I2PDPermsAskerActivity extends AppCompatActivity {
startActivity(new Intent(this, I2PDActivity.class));
finish();
}
+
+ private static final int SHOW_EXPLANATION_REQUEST = 1; // The request code
+ private void showExplanation() {
+ Intent intent = new Intent(this, I2PDPermsExplanationActivity.class);
+ startActivityForResult(intent, SHOW_EXPLANATION_REQUEST);
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ // Check which request we're responding to
+ if (requestCode == SHOW_EXPLANATION_REQUEST) {
+ // Make sure the request was successful
+ if (resultCode == RESULT_OK) {
+ // Request the permission
+ Method method_requestPermissions;
+ try {
+ method_requestPermissions =
+ getClass().getMethod("requestPermissions", String[].class, int.class);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(e);
+ }
+ try {
+ method_requestPermissions.invoke(this,
+ new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
+ PERMISSION_WRITE_EXTERNAL_STORAGE);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ finish(); //close the app
+ }
+ }
+ }
}
diff --git a/android/src/org/purplei2p/i2pd/I2PDPermsExplanationActivity.java b/android/src/org/purplei2p/i2pd/I2PDPermsExplanationActivity.java
new file mode 100644
index 00000000..d1641e78
--- /dev/null
+++ b/android/src/org/purplei2p/i2pd/I2PDPermsExplanationActivity.java
@@ -0,0 +1,38 @@
+package org.purplei2p.i2pd;
+
+import android.app.ActionBar;
+import android.content.Intent;
+import android.os.Bundle;
+import android.app.Activity;
+import android.view.View;
+import android.widget.Button;
+
+public class I2PDPermsExplanationActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_perms_explanation);
+ ActionBar actionBar = getActionBar();
+ if(actionBar!=null)actionBar.setHomeButtonEnabled(false);
+ Button button_ok = (Button) findViewById(R.id.button_ok);
+ button_ok.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ returnFromActivity();
+ }
+ });
+ }
+
+ private void returnFromActivity() {
+ Intent data = new Intent();
+ Activity parent = getParent();
+ if (parent == null) {
+ setResult(Activity.RESULT_OK, data);
+ } else {
+ parent.setResult(Activity.RESULT_OK, data);
+ }
+ finish();
+ }
+
+}