@@ -1776,38 +1776,33 @@ private void writeServicePermissionHandlers(final PrintWriter writer, String[] p
1776
1776
writer .println (" permIntent.putExtra(KEY_RESULT_RECEIVER, resultReceiver);" );
1777
1777
writer .println (" permIntent.putExtra(KEY_PERMISSIONS, permissions);" );
1778
1778
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
+ }
1806
1801
writer .println (" }" );
1807
1802
}
1808
1803
1809
1804
// 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)
1811
1806
writer .println (" public static class PermissionRequestActivity extends Activity {" );
1812
1807
if (permissions .length > 0 ) {
1813
1808
writer .println (" ResultReceiver resultReceiver;" );
0 commit comments