@@ -92,6 +92,8 @@ public final class TermuxActivity extends Activity implements ServiceConnection
92
92
93
93
private static final int MAX_SESSIONS = 8 ;
94
94
95
+ private static final int REQUESTCODE_PERMISSION_STORAGE = 1234 ;
96
+
95
97
private static final String RELOAD_STYLE_ACTION = "com.termux.app.reload_style" ;
96
98
97
99
/** The main view of the activity showing the terminal. Initialized in onCreate(). */
@@ -130,6 +132,10 @@ public final class TermuxActivity extends Activity implements ServiceConnection
130
132
public void onReceive (Context context , Intent intent ) {
131
133
if (mIsVisible ) {
132
134
String whatToReload = intent .getStringExtra (RELOAD_STYLE_ACTION );
135
+ if ("storage" .equals (whatToReload )) {
136
+ if (ensureStoragePermissionGranted ()) TermuxInstaller .setupStorageSymlinks (TermuxActivity .this );
137
+ return ;
138
+ }
133
139
if (whatToReload == null || "colors" .equals (whatToReload )) mTerminalView .checkForColors ();
134
140
if (whatToReload == null || "font" .equals (whatToReload )) mTerminalView .checkForTypeface ();
135
141
if (whatToReload == null || "settings" .equals (whatToReload )) mSettings .reloadFromProperties (TermuxActivity .this );
@@ -139,11 +145,17 @@ public void onReceive(Context context, Intent intent) {
139
145
140
146
/** For processes to access shared internal storage (/sdcard) we need this permission. */
141
147
@ TargetApi (Build .VERSION_CODES .M )
142
- public void ensureStoragePermissionGranted () {
148
+ public boolean ensureStoragePermissionGranted () {
143
149
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
144
- if (checkSelfPermission (android .Manifest .permission .WRITE_EXTERNAL_STORAGE ) != PackageManager .PERMISSION_GRANTED ) {
145
- requestPermissions (new String []{Manifest .permission .WRITE_EXTERNAL_STORAGE }, 1234 );
150
+ if (checkSelfPermission (android .Manifest .permission .WRITE_EXTERNAL_STORAGE ) == PackageManager .PERMISSION_GRANTED ) {
151
+ return true ;
152
+ } else {
153
+ requestPermissions (new String []{Manifest .permission .WRITE_EXTERNAL_STORAGE }, REQUESTCODE_PERMISSION_STORAGE );
154
+ return false ;
146
155
}
156
+ } else {
157
+ // Always granted before Android 6.0.
158
+ return true ;
147
159
}
148
160
}
149
161
@@ -327,8 +339,6 @@ public void onClick(View v) {
327
339
mTerminalView .checkForTypeface ();
328
340
mTerminalView .checkForColors ();
329
341
330
- TermuxInstaller .setupStorageSymlinks (this );
331
-
332
342
mBellSoundId = mBellSoundPool .load (this , R .raw .bell , 1 );
333
343
}
334
344
@@ -772,6 +782,13 @@ public void onClick(DialogInterface dialog, int which) {
772
782
}
773
783
}
774
784
785
+ @ Override
786
+ public void onRequestPermissionsResult (int requestCode , String permissions [], int [] grantResults ) {
787
+ if (requestCode == REQUESTCODE_PERMISSION_STORAGE && grantResults .length > 0 && grantResults [0 ] == PackageManager .PERMISSION_GRANTED ) {
788
+ TermuxInstaller .setupStorageSymlinks (this );
789
+ }
790
+ }
791
+
775
792
void toggleImmersive () {
776
793
boolean newValue = !mSettings .isFullScreen ();
777
794
mSettings .setFullScreen (this , newValue );
0 commit comments