Skip to content

Commit dcd95c8

Browse files
committed
using notifications fixes permission request on watch faces
1 parent b43fdb7 commit dcd95c8

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

src/processing/mode/android/AndroidBuild.java

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,38 +1776,33 @@ private void writeServicePermissionHandlers(final PrintWriter writer, String[] p
17761776
writer.println(" permIntent.putExtra(KEY_RESULT_RECEIVER, resultReceiver);");
17771777
writer.println(" permIntent.putExtra(KEY_PERMISSIONS, permissions);");
17781778
writer.println(" permIntent.putExtra(KEY_REQUEST_CODE, requestCode);");
1779-
writer.println(" permIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);");
1780-
// writer.println(" TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);");
1781-
// writer.println(" stackBuilder.addNextIntent(permIntent);");
1782-
// writer.println(" PendingIntent permPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);");
1783-
// writer.println(" NotificationCompat.Builder builder = new NotificationCompat.Builder(this)");
1784-
// writer.println(" .setSmallIcon(R.drawable.icon)");
1785-
// writer.println(" .setContentTitle(\"Requesting permissions\")");
1786-
// writer.println(" .setContentText(\"The app need permissions to work properly\")");
1787-
// writer.println(" .setOngoing(true)");
1788-
// writer.println(" .setAutoCancel(true)");
1789-
// writer.println(" .setWhen(0)");
1790-
// writer.println(" .setContentIntent(permPendingIntent)");
1791-
// writer.println(" .setStyle(null);");
1792-
// writer.println(" NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);");
1793-
// writer.println(" notificationManager.notify(requestCode, builder.build());");
1794-
1795-
// writer.println(" AlertDialog.Builder builder = new AlertDialog.Builder(this);");
1796-
// writer.println(" builder.setMessage(\"The app needs some permissions to run.\")");
1797-
// writer.println(" .setCancelable(false)");
1798-
// writer.println(" .setPositiveButton(\"OK\", new DialogInterface.OnClickListener() {");
1799-
// writer.println(" public void onClick(DialogInterface dialog, int id) {");
1800-
// writer.println(" startActivity(permIntent);");
1801-
// writer.println(" }");
1802-
// writer.println(" });");
1803-
// writer.println(" AlertDialog alert = builder.create();");
1804-
// writer.println(" alert.show();");
1805-
writer.println(" startActivity(permIntent);");
1779+
1780+
if (appComponent == WATCHFACE) {
1781+
// Create a notification on watch faces, otherwise it does not work.
1782+
writer.println(" TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);");
1783+
writer.println(" stackBuilder.addNextIntent(permIntent);");
1784+
writer.println(" PendingIntent permPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);");
1785+
writer.println(" NotificationCompat.Builder builder = new NotificationCompat.Builder(this)");
1786+
writer.println(" .setSmallIcon(R.drawable.icon)");
1787+
writer.println(" .setContentTitle(\"Requesting permissions\")");
1788+
writer.println(" .setContentText(\"The app need permissions to work properly\")");
1789+
writer.println(" .setOngoing(true)");
1790+
writer.println(" .setAutoCancel(true)");
1791+
writer.println(" .setWhen(0)");
1792+
writer.println(" .setContentIntent(permPendingIntent)");
1793+
writer.println(" .setStyle(null);");
1794+
writer.println(" NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);");
1795+
writer.println(" notificationManager.notify(requestCode, builder.build());");
1796+
} else {
1797+
// Just show the dialog requesting the permissions
1798+
writer.println(" permIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);");
1799+
writer.println(" startActivity(permIntent);");
1800+
}
18061801
writer.println(" }");
18071802
}
18081803

18091804
// Activity that triggers the ActivityCompat.requestPermissions() call
1810-
// (still needs the class declaration because it is the maninfest file)
1805+
// (still needs the class declaration because it is the manifest file)
18111806
writer.println(" public static class PermissionRequestActivity extends Activity {");
18121807
if (permissions.length > 0) {
18131808
writer.println(" ResultReceiver resultReceiver;");

0 commit comments

Comments
 (0)