i am trying to use this code.
public synchronized void onActivityResult(final int requestCode, int resultCode,
final Intent data) {
String filePath = null;
if (resultCode == Activity.RESULT_OK) {
switch (requestCode) {
case RESULT_MEMORY_SAVE:
filePath = data.getDataString();
copyFileForReceipts(filePath,pathOfReceipts);
Now filePath is a String , Debugger shows its value as "content://media/external/images/media/133"
Next i am trying to use this:
sourceLocation = filePath;
File afile = new File(sourceLocation);
File bfile = new File(targetLocation + "file.jpg");
inStream = new FileInputStream(afile.getName()); //Gives exception
outStream = new FileOutputStream(bfile.getName());
Its gives an exception of FileNotFound exception. I have tried removing .getName() too.
Please tell me where am i wrong.
Regards
instead of using setData and getDataString, you should put the file path and retrieve it as follow:
to add path in result producing activity:
and to retrieve path:
and its a good practice to check the existence of file before doing anything further on it: