Skip to content

Commit 774453f

Browse files
committed
add onRequestPermissionsResult() only if SDK >= 23, fix #268
1 parent 40a762e commit 774453f

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

src/processing/mode/android/AndroidBuild.java

+26-24
Original file line numberDiff line numberDiff line change
@@ -978,30 +978,32 @@ private void writeMainActivity(final File srcDirectory, String[] permissions) {
978978
writer.println(" }");
979979
writer.println(" }");
980980

981-
// The event handler for the permission result
982-
writer.println(" @Override");
983-
writer.println(" public void onRequestPermissionsResult(int requestCode,");
984-
writer.println(" String permissions[], int[] grantResults) {");
985-
writer.println(" if (requestCode == REQUEST_PERMISSIONS) {");
986-
writer.println(" if (grantResults.length > 0) {");
987-
writer.println(" for (int i = 0; i < grantResults.length; i++) {");
988-
writer.println(" if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {");
989-
writer.println(" AlertDialog.Builder builder = new AlertDialog.Builder(this);");
990-
writer.println(" builder.setMessage(\"Some permissions needed by the app were not granted, so it might not work as intended.\")");
991-
writer.println(" .setCancelable(false)");
992-
writer.println(" .setPositiveButton(\"OK\", new DialogInterface.OnClickListener() {");
993-
writer.println(" public void onClick(DialogInterface dialog, int id) {");
994-
// writer.println(" finish();");
995-
writer.println(" }");
996-
writer.println(" });");
997-
writer.println(" AlertDialog alert = builder.create();");
998-
writer.println(" alert.show();");
999-
writer.println(" }");
1000-
writer.println(" }");
1001-
writer.println(" fragment.onPermissionsGranted();");
1002-
writer.println(" }");
1003-
writer.println(" }");
1004-
writer.println(" }");
981+
if (Integer.parseInt(sdkVersion) >= 23) {
982+
// The event handler for the permission result
983+
writer.println(" @Override");
984+
writer.println(" public void onRequestPermissionsResult(int requestCode,");
985+
writer.println(" String permissions[], int[] grantResults) {");
986+
writer.println(" if (requestCode == REQUEST_PERMISSIONS) {");
987+
writer.println(" if (grantResults.length > 0) {");
988+
writer.println(" for (int i = 0; i < grantResults.length; i++) {");
989+
writer.println(" if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {");
990+
writer.println(" AlertDialog.Builder builder = new AlertDialog.Builder(this);");
991+
writer.println(" builder.setMessage(\"Some permissions needed by the app were not granted, so it might not work as intended.\")");
992+
writer.println(" .setCancelable(false)");
993+
writer.println(" .setPositiveButton(\"OK\", new DialogInterface.OnClickListener() {");
994+
writer.println(" public void onClick(DialogInterface dialog, int id) {");
995+
// writer.println(" finish();");
996+
writer.println(" }");
997+
writer.println(" });");
998+
writer.println(" AlertDialog alert = builder.create();");
999+
writer.println(" alert.show();");
1000+
writer.println(" }");
1001+
writer.println(" }");
1002+
writer.println(" fragment.onPermissionsGranted();");
1003+
writer.println(" }");
1004+
writer.println(" }");
1005+
writer.println(" }");
1006+
}
10051007

10061008
writer.println("}");
10071009
writer.flush();

0 commit comments

Comments
 (0)