diff --git a/app/src/main/java/com/limelight/preferences/StreamSettings.java b/app/src/main/java/com/limelight/preferences/StreamSettings.java index 1234c3f55..a4ff036e1 100755 --- a/app/src/main/java/com/limelight/preferences/StreamSettings.java +++ b/app/src/main/java/com/limelight/preferences/StreamSettings.java @@ -721,6 +721,28 @@ public boolean onPreferenceClick(Preference preference) { } }); + findPreference("import_https_data_crt_file").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.setType("*/*"); + startActivityForResult(intent, READ_DATA_CRT_REQUEST_CODE); + return false; + } + }); + + findPreference("import_https_data_key_file").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.setType("*/*"); + startActivityForResult(intent, READ_DATA_KEY_REQUEST_CODE); + return false; + } + }); + findPreference("import_special_button_file").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { @@ -776,6 +798,44 @@ public boolean onPreferenceClick(Preference preference) { } }); + findPreference("export_https_data_crt_file").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + File dataFile=new File(getActivity().getFilesDir().getAbsolutePath()+ File.separator + "client.crt"); + if(!dataFile.exists()){ + return false; + } + Uri uri; + Intent intent = new Intent(Intent.ACTION_SEND); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + String authority= BuildConfig.APPLICATION_ID+".fileprovider"; + uri= FileProvider.getUriForFile(getActivity(),authority,dataFile); + intent.putExtra(Intent.EXTRA_STREAM, uri); + intent.setType("*/*"); + startActivity(Intent.createChooser(intent,"保存数据文件")); + return false; + } + }); + + findPreference("export_https_data_key_file").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + File dataFile=new File(getActivity().getFilesDir().getAbsolutePath()+ File.separator + "client.key"); + if(!dataFile.exists()){ + return false; + } + Uri uri; + Intent intent = new Intent(Intent.ACTION_SEND); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + String authority= BuildConfig.APPLICATION_ID+".fileprovider"; + uri= FileProvider.getUriForFile(getActivity(),authority,dataFile); + intent.putExtra(Intent.EXTRA_STREAM, uri); + intent.setType("*/*"); + startActivity(Intent.createChooser(intent,"保存数据文件")); + return false; + } + }); + findPreference("pref_axi_test").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override @@ -841,6 +901,10 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { int READ_DATABASE_REQUEST_CODE=1003; + int READ_DATA_CRT_REQUEST_CODE=1004; + + int READ_DATA_KEY_REQUEST_CODE=1005; + @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); @@ -914,6 +978,39 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { } return; } + + if (requestCode == READ_DATA_CRT_REQUEST_CODE && resultCode == Activity.RESULT_OK &&data.getData()!=null) { + try { + Uri uri = data.getData(); + File dataBaseFile= null; + String displayName = "client.crt"; + dataBaseFile=new File(getActivity().getFilesDir().getAbsolutePath(), displayName); + FileUriUtils.copyUriToInternalStorage(getActivity(),uri,dataBaseFile); + Toast.makeText(getActivity(),"导入成功!",Toast.LENGTH_SHORT).show(); + } catch (Exception e) { + e.printStackTrace(); + Toast.makeText(getActivity(),"出错啦~"+e.getMessage(),Toast.LENGTH_SHORT).show(); + } + return; + + } + + if (requestCode == READ_DATA_KEY_REQUEST_CODE && resultCode == Activity.RESULT_OK &&data.getData()!=null) { + try { + Uri uri = data.getData(); + File dataBaseFile= null; + String displayName = "client.key"; + dataBaseFile=new File(getActivity().getFilesDir().getAbsolutePath(), displayName); + FileUriUtils.copyUriToInternalStorage(getActivity(),uri,dataBaseFile); + Toast.makeText(getActivity(),"导入成功!",Toast.LENGTH_SHORT).show(); + } catch (Exception e) { + e.printStackTrace(); + Toast.makeText(getActivity(),"出错啦~"+e.getMessage(),Toast.LENGTH_SHORT).show(); + } + return; + + } + } diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 5a0376107..e8c10804d 100755 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -515,18 +515,6 @@ android:summary="每次都会覆盖原来的,请注意备份。" /> - - - - + + + + + + + + + + + + + + + + +