comparison app/src/main/java/com/five_ten_sg/connectbot/HostListActivity.java @ 499:267e72057707

updates for android10+
author Carl Byington <carl@five-ten-sg.com>
date Tue, 07 Jun 2022 16:04:52 -0700
parents 3feac274a27b
children 11d714165a2d
comparison
equal deleted inserted replaced
498:3feac274a27b 499:267e72057707
174 getResources().getText(R.string.title_hosts_list))); 174 getResources().getText(R.string.title_hosts_list)));
175 this.prefs = PreferenceManager.getDefaultSharedPreferences(this); 175 this.prefs = PreferenceManager.getDefaultSharedPreferences(this);
176 176
177 // ask for permissions, must match AndroidManifest.xml 177 // ask for permissions, must match AndroidManifest.xml
178 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 178 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
179 String [] perms = {Manifest.permission.INTERNET, 179 get_permissions(new String[] {Manifest.permission.ACCESS_NETWORK_STATE,
180 Manifest.permission.ACCESS_NETWORK_STATE, 180 Manifest.permission.INTERNET,
181 Manifest.permission.WAKE_LOCK}; 181 Manifest.permission.WAKE_LOCK});
182 checkp(perms);
183 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { 182 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
184 if (!Environment.isExternalStorageManager()) { 183 get_storage_manager();
185 try {
186 Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
187 intent.addCategory("android.intent.category.DEFAULT");
188 intent.setData(Uri.parse(String.format("package:%s",getApplicationContext().getPackageName())));
189 startActivity(intent);
190 } catch (Exception e) {
191 Intent intent = new Intent();
192 intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
193 startActivity(intent);
194 }
195 }
196 } 184 }
197 else { 185 else {
198 String [] perms2 = {Manifest.permission.WRITE_EXTERNAL_STORAGE}; 186 get_permissions(new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE});
199 checkp(perms2);
200 } 187 }
201 } 188 }
202 189
203 // detect HTC Dream and apply special preferences 190 // detect HTC Dream and apply special preferences
204 if (Build.MANUFACTURER.equals("HTC") && Build.DEVICE.equals("dream")) { 191 if (Build.MANUFACTURER.equals("HTC") && Build.DEVICE.equals("dream")) {
289 contents.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 276 contents.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
290 startActivity(contents); 277 startActivity(contents);
291 } 278 }
292 } 279 }
293 280
294 public void checkp(String [] perms) { 281 public void get_storage_manager() {
282 if (!Environment.isExternalStorageManager()) {
283 try {
284 Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
285 intent.addCategory("android.intent.category.DEFAULT");
286 intent.setData(Uri.parse(String.format("package:%s",getApplicationContext().getPackageName())));
287 startActivityForResult(intent, 31415);
288 } catch (Exception e) {
289 Intent intent = new Intent();
290 intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
291 startActivityForResult(intent, 31415);
292 }
293 }
294 }
295
296 @Override
297 protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
298 super.onActivityResult(requestCode, resultCode, data);
299 if (requestCode == 31415) {
300 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
301 if (!Environment.isExternalStorageManager()) {
302 Toast.makeText(this, "Allow permission for storage access!", Toast.LENGTH_SHORT).show();
303 }
304 }
305 }
306 }
307
308 public void get_permissions(String [] perms) {
295 boolean need = false; 309 boolean need = false;
296 for (String perm : perms) { 310 for (String perm : perms) {
297 if (ContextCompat.checkSelfPermission(this, perm) != PackageManager.PERMISSION_GRANTED) { 311 if (ContextCompat.checkSelfPermission(this, perm) != PackageManager.PERMISSION_GRANTED) {
298 need = true; 312 need = true;
299 } 313 }