|
@@ -490,18 +490,18 @@ public class Config extends AppCompatActivity
|
|
|
edit_text = (EditText) findViewById(R.id.editsearch);
|
|
|
|
|
|
//选择本地文件
|
|
|
- btnLocalFileButton = (Button) findViewById(R.id.localfile);
|
|
|
- btnLocalFileButton.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- //ActivityCompat.requestPermissions( Config.this, new String[]{android
|
|
|
- // .Manifest.permission.READ_EXTERNAL_STORAGE}, 2);
|
|
|
- Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
|
|
- intent.setType("*/*");//设置类型,我这里是任意类型,任意后缀的可以这样写。
|
|
|
- intent.addCategory(Intent.CATEGORY_OPENABLE);
|
|
|
- startActivityForResult(intent, 2);
|
|
|
- }
|
|
|
- });
|
|
|
+ //btnLocalFileButton = (Button) findViewById(R.id.localfile);
|
|
|
+ //btnLocalFileButton.setOnClickListener(new View.OnClickListener() {
|
|
|
+ // @Override
|
|
|
+ // public void onClick(View v) {
|
|
|
+ // //ActivityCompat.requestPermissions( Config.this, new String[]{android
|
|
|
+ // // .Manifest.permission.READ_EXTERNAL_STORAGE}, 2);
|
|
|
+ // Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
|
|
+ // intent.setType("*/*");//设置类型,我这里是任意类型,任意后缀的可以这样写。
|
|
|
+ // intent.addCategory(Intent.CATEGORY_OPENABLE);
|
|
|
+ // startActivityForResult(intent, 2);
|
|
|
+ // }
|
|
|
+ //});
|
|
|
|
|
|
//选择U盘文件
|
|
|
btnUDiskFileButton = (Button) findViewById(R.id.udiskfile);
|
|
@@ -510,7 +510,7 @@ public class Config extends AppCompatActivity
|
|
|
public void onClick(View v) {
|
|
|
//ActivityCompat.requestPermissions( Config.this, new String[]{android
|
|
|
// .Manifest.permission.READ_EXTERNAL_STORAGE}, 2);
|
|
|
- Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
|
|
+ Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
|
|
intent.setType("*/*");//设置类型,我这里是任意类型,任意后缀的可以这样写。
|
|
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
|
|
startActivityForResult(intent, 1);
|
|
@@ -1678,7 +1678,7 @@ public class Config extends AppCompatActivity
|
|
|
}
|
|
|
*/
|
|
|
|
|
|
- protected void onActivityResult ( int requestCode, int resultCode, Intent data){
|
|
|
+ protected void onActivityResult ( int requestCode, int resultCode, Intent resultData){
|
|
|
if (resultCode == Activity.RESULT_OK) {
|
|
|
|
|
|
int permission_write = ContextCompat.checkSelfPermission(Config.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
|
@@ -1692,6 +1692,38 @@ public class Config extends AppCompatActivity
|
|
|
android.Manifest.permission.READ_EXTERNAL_STORAGE}, 3);
|
|
|
}
|
|
|
|
|
|
+ String configString = "";
|
|
|
+
|
|
|
+ if (requestCode == 1 && resultCode == Activity.RESULT_OK) { //U 盘 文 件
|
|
|
+
|
|
|
+ Uri uri = null;
|
|
|
+ if (resultData != null){
|
|
|
+ uri = resultData.getData();
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ InputStream inputStream = getContentResolver().openInputStream(uri);
|
|
|
+ BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
|
|
+ String line;
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+
|
|
|
+ while ((line = reader.readLine()) != null){
|
|
|
+ stringBuilder.append(line);
|
|
|
+ }
|
|
|
+
|
|
|
+ reader.close();
|
|
|
+
|
|
|
+ configString = stringBuilder.toString();
|
|
|
+
|
|
|
+ //edit_search.setText(fileData);
|
|
|
+ edit_search.setText(uri.getPath());
|
|
|
+
|
|
|
+ } catch (IOException c) {
|
|
|
+ edit_search.setText(uri.getPath() + "——" + getResources().getString(R.string.invalidfile));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /*
|
|
|
StringBuffer buffer = new StringBuffer();
|
|
|
String configString = "";
|
|
|
Uri uri = data.getData();
|
|
@@ -1786,7 +1818,7 @@ public class Config extends AppCompatActivity
|
|
|
return;
|
|
|
}
|
|
|
} //end of else if (requestCode == 2)
|
|
|
-
|
|
|
+ */
|
|
|
/*
|
|
|
Uri uri = data.getData();
|
|
|
File file = new File(uri.getPath());
|
|
@@ -1856,6 +1888,7 @@ public class Config extends AppCompatActivity
|
|
|
}
|
|
|
|
|
|
ReadCfgRam(stringCfgArr);
|
|
|
+
|
|
|
} //end of if (resultCode == Activity.RESULT_OK)
|
|
|
}
|
|
|
|