comparison app/src/main/java/com/five_ten_sg/connectbot/HostListActivity.java @ 500:11d714165a2d

updates for android10+
author Carl Byington <carl@five-ten-sg.com>
date Tue, 07 Jun 2022 16:10:58 -0700
parents 267e72057707
children aee5f34cc2db
comparison
equal deleted inserted replaced
499:267e72057707 500:11d714165a2d
69 import android.widget.ArrayAdapter; 69 import android.widget.ArrayAdapter;
70 import android.widget.ImageView; 70 import android.widget.ImageView;
71 import android.widget.ListView; 71 import android.widget.ListView;
72 import android.widget.Spinner; 72 import android.widget.Spinner;
73 import android.widget.TextView; 73 import android.widget.TextView;
74 import android.widget.Toast;
74 import android.content.pm.PackageManager; 75 import android.content.pm.PackageManager;
75 import android.os.Build; 76 import android.os.Build;
76 import android.Manifest; 77 import android.Manifest;
77 import android.support.v4.app.ActivityCompat; 78 import android.support.v4.app.ActivityCompat;
78 import android.support.v4.content.ContextCompat; 79 import android.support.v4.content.ContextCompat;
79 80
80 public class HostListActivity extends ListActivity { 81 public class HostListActivity extends ListActivity {
81 protected static final String TAG = "ConnectBot.HostListActivity"; 82 protected static final String TAG = "ConnectBot.HostListActivity";
82 public final static int REQUEST_EDIT = 1; 83 public final static int REQUEST_EDIT = 1;
83 public final static int REQUEST_EULA = 2; 84 public final static int REQUEST_EULA = 2;
85 public final static int REQUEST_STORAGEMANAGER = 3;
84 86
85 protected TerminalManager bound = null; 87 protected TerminalManager bound = null;
86 88
87 protected HostDatabase hostdb; 89 protected HostDatabase hostdb;
88 private List<HostBean> hosts; 90 private List<HostBean> hosts;
160 this.finish(); 162 this.finish();
161 } 163 }
162 } 164 }
163 else if (requestCode == REQUEST_EDIT) { 165 else if (requestCode == REQUEST_EDIT) {
164 updateList(); 166 updateList();
167 }
168 else if (requestCode == REQUEST_STORAGE_MANAGER) {
169 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
170 if (!Environment.isExternalStorageManager()) {
171 Toast.makeText(this, "Allow permission for storage access!", Toast.LENGTH_SHORT).show();
172 }
173 }
165 } 174 }
166 } 175 }
167 176
168 @Override 177 @Override
169 public void onCreate(Bundle icicle) { 178 public void onCreate(Bundle icicle) {
282 if (!Environment.isExternalStorageManager()) { 291 if (!Environment.isExternalStorageManager()) {
283 try { 292 try {
284 Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION); 293 Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
285 intent.addCategory("android.intent.category.DEFAULT"); 294 intent.addCategory("android.intent.category.DEFAULT");
286 intent.setData(Uri.parse(String.format("package:%s",getApplicationContext().getPackageName()))); 295 intent.setData(Uri.parse(String.format("package:%s",getApplicationContext().getPackageName())));
287 startActivityForResult(intent, 31415); 296 startActivityForResult(intent, REQUEST_STORAGE_MANAGER);
288 } catch (Exception e) { 297 } catch (Exception e) {
289 Intent intent = new Intent(); 298 Intent intent = new Intent();
290 intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION); 299 intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
291 startActivityForResult(intent, 31415); 300 startActivityForResult(intent, REQUEST_STORAGE_MANAGER);
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 } 301 }
305 } 302 }
306 } 303 }
307 304
308 public void get_permissions(String [] perms) { 305 public void get_permissions(String [] perms) {