Home > Mobile >  Android to the U disk write data problem!!!!!! (we discussed together)
Android to the U disk write data problem!!!!!! (we discussed together)

Time:10-16


first to introduce the whole environment:
Hardware is the android box:
System is android 5.1.1, these are the manufacturer of custom,
Screen monitors interface is to use a computer and connected, and the box
(ps: I am as a little word a little white, like the bosses also many learning place, so can you provide the information I provide, hope your bosses can answer for me, or colleagues to discuss learning)

followed by the text:
The original requirement: save the file to the SD card (this simple, also achieved),

New requirements: it is a when saving files to judge whether there is a U disk, there were, also save a into the U disk (like the figure above, the android box is to be able to pick up U disk, I don't know whether the phone OTG even U disk is a nature,)

what I did:
1. Just got demand for you is very simple, not is to write a path, well preserved,
In the file manager system at first to see the U disk path
Hence:
 private String USB="/MNT/usbdisk"; 
Private Boolean saveDrawToFile (Bitmap Bitmap, String fileName) {
The File dir=new File (USB);
if (! Dir. The exists ()) {
Dir. The file.mkdirs ();
}
The File File=new File (dir, fileName);
Return FileWriter. WriteBitmap (file, bitmap);
//writeBitmap -- -- -- -- -- -- -- -- & gt; To the specified file is written to bitmap
}

Results: don't want to fail,

2. The above methods failed, I was thinking maybe I think too simple, this is there could be a path problem, and cause to fail?
Hence:
(all kinds of baidu: how to get U disk, external storage path)
This article could be reference for the: http://blog.csdn.net/u014587769/article/details/52072608
Information access to all the mount point (ps: for the first time know this word: mount, although seems to still don't quite understand what meaning)
I'll have to get all the mount point information of address to take out
Be:
/storage/emulated/0 
/storage/sdcard1
/storage/usbdisk
/storage/usbdisk2
/storage/usbdisk3
/storage/usbdisk4

Question again (small white really step a bumpy around), why use system file manager to see the address is/MNT/usbdisk but here for/storage/usbdisk, MNT and storage to distinguish? The Internet again, probably a little understanding, and then think that hope is coming, thought there must be an address above is the U disk, put the above address to try again,,,
Results: the failed

3. Then will want to is actually the address is correct, just write not successful?
In order to confirm the idea then I will go to read the first one of U disk file, to see if I can read if return true
 public Boolean fileIsExists (String path) {
Try {
The File f=new File (path);
if(! F.e xists ()) {
return false;
}

} the catch (Exception e) {
//TODO: handle the exception
return false;
}
return true;
}
Toast. MakeText (ContextHolder. GetContext (), "file exists -- -- -- -- -- -- -- -- -- & gt;" + fileIsExists (USB + File. The separator + "copy. The bat"), Toast. LENGTH_LONG.) the show ();

Results: the display file exists, description/storage/usbdisk said the address is correct,

4. The feeling is getting closer and closer to the cause of the problem, the most likely problem is no write access!!!!!
At first I thought whether AndroidMainfest. XML spill what permissions? Just add after, search after the
 & lt; USES - the permission of the android: name="android. Permission. WRITE_MEDIA_STORAGE"/& gt; 
also add the permissions or not
I'll check back: (write access questions about U disk), but online method seems to be the same, what changes the system/etc/permissions/platform. The XML file, modify the framework in what ah, there are also said to RE manager to modify what (ps: maybe to every user install the app to get inside to do these things, and it makes me very confused) although up to now I don't even know where these files is 0.0 but I feel these are not the answer, which also refer to this article and encountered problems related http://bbs.csdn.net/topics/390259121

5. Later find U disk position, RE manager failed to create a folder to create, further evidence is not have write access, RE manager was no root tips, and then come back again to want to have to file system manager, I create the folder can be in it, delete the things what operation, check again how to increase root access to a single app, and each kind of partial bottom method, (as a small white look at these is 0.0) will be a little difficult

Wrote good,,,, so much, summed up down the question is: I have encountered this problem is to have no write access lead to? No write access is because they have no root? So what should I do? Or is other reason lead to? Also see a lot of information online, not in some way, you see is not very good, writing is no head no tail, and also, every brother please help to reassure, or what ideas we discuss,


Ask a question actually unconsciously wrote so many typesetting may still have some miscellaneous don't know whether your bosses have the patience to read, thank you in advance,

CodePudding user response:

bosses

CodePudding user response:

Is too long, you don't like the

CodePudding user response:

Their top once,,,

CodePudding user response:

The adb operations to create a file directly? In addition you will write files an error?

CodePudding user response:

reference 4 floor u013923270 response:
adb operations to create a file directly? In addition you will write files an error?


The first problem,, the adb operations directly, didn't try, also do not know how to operate the
System at the second, I use the file manager write files won't be an error, then RE manager to create the folder is an error, was no root tip

Finally, thank you

CodePudding user response:

A daily top

CodePudding user response:

Bosses,,

CodePudding user response:

Your problem solved? I recently also should make U disk import and export data

CodePudding user response:

The building Lord problem solved, recently also need to make a USB peripheral devices will be written to the file

CodePudding user response:

Access to the same usb path if it is prefabricated for the system application is possible, but not a third party applications

CodePudding user response:

Attention, always waiting for bosses

CodePudding user response:

Promoted to system APP permissions, and the signature

CodePudding user response:

Could you tell me the blogger problem solved? I also encountered the same problem, the feeling is a: two possible access to the U disk path is wrong; 2: no U disk read and write permissions,

CodePudding user response:

Android5.0 above system has not support developers write mobile casually external storage (contain tf card, an external usb otg, etc.), must use specific methods to read and write, the use of search DocumentFile yourself...
Only a fixed operation or directory: Android/data/package/... , which you can literally do operation, but the app deleted, these data will be automatically deleted,

CodePudding user response:

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related