launchSomeActivity = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
if (result.getResultCode() == Activity.RESULT_OK) {
Intent data = result.getData();
File sourceLocation= new File (data.getData().getPath());
txtbxname.setText(sourceLocation.getName());
File targetLocation= new File ("/storage/sdcard0/Pictures/Screenshots/");
InputStream in = null;
OutputStream out=null;
try {
in = new FileInputStream(sourceLocation);
out= new FileOutputStream(targetLocation);
} catch (IOException e) {
e.printStackTrace();
}
// Copy the bits from instream to outstream
byte[] buf = new byte[1024];
int len;
try {
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
} catch (IOException e){
e.printStackTrace();
}
}
}
});
new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
if (result.getResultCode() == Activity.RESULT_OK) {
Intent data = result.getData();
File sourceLocation= new File (data.getData().getPath());
txtbxname.setText(sourceLocation.getName());
File targetLocation= new File ("/storage/sdcard0/Pictures/Screenshots/");
InputStream in = null;
OutputStream out=null;
try {
in = new FileInputStream(sourceLocation);
out= new FileOutputStream(targetLocation);
} catch (IOException e) {
e.printStackTrace();
}
// Copy the bits from instream to outstream
byte[] buf = new byte[1024];
int len;
try {
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
} catch (IOException e){
e.printStackTrace();
}
}
}
});
