Nexus 4가 MTP를 통해 파일을 표시하지 않음
간단한 XML 파일을 SD 카드에 작성하려고하는데 Nexus 4가 파일을 작성하지만 Windows 7을 사용하는 MTP 프로토콜을 통해 볼 수 없다는 것을 알았습니다.
암호:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
CustomerQueryRqType customerQueryRequest = new CustomerQueryRqType();
Serializer serializer = new Persister();
File myFile = new File(Environment.getExternalStorageDirectory() + "/customerQueryRequest.xml");
try {
boolean created = myFile.createNewFile();
serializer.write(customerQueryRequest, myFile);
} catch (Exception e) {
e.printStackTrace();
}
}
Astro File Manager를 사용하여 전화기 자체에서 파일을 볼 수 있습니다.
그러나 Windows는 그것을 보지 못합니다 ... :
adb shell
디렉토리에 다음이 표시됩니다.
ls -l
drwxrwxr-x root sdcard_rw 1970-01-16 20:51 Alarms
drwxrwxr-x root sdcard_rw 1970-01-16 20:51 Android
drwxrwxr-x root sdcard_rw 2012-11-21 19:30 DCIM
drwxrwxr-x root sdcard_rw 1970-01-16 20:51 Download
drwxrwxr-x root sdcard_rw 1970-01-16 20:51 Movies
drwxrwxr-x root sdcard_rw 1970-01-16 20:51 Music
drwxrwxr-x root sdcard_rw 1970-01-16 20:51 Notifications
drwxrwxr-x root sdcard_rw 2012-11-19 12:06 Pictures
drwxrwxr-x root sdcard_rw 1970-01-16 20:51 Podcasts
drwxrwxr-x root sdcard_rw 2012-11-19 13:22 Ringtones
drwxrwxr-x root sdcard_rw 2012-11-19 14:33 bluetooth
-rw-rw-r-- root sdcard_rw 79 2012-12-05 22:26 customerQueryRequest.xml
drwxrwxr-x root sdcard_rw 2012-11-20 02:50 data
-rw-rw-r-- root sdcard_rw 11394 2012-11-19 13:54 eightpen_custom_gestures
drwxrwxr-x root sdcard_rw 2012-11-19 13:17 media
Nexus 4는 어떻게 되나요? Windows에서 내 물건을 숨기는 이유는 무엇입니까?
MTP를 통한 Android USB 파일 액세스에 영향을 미치는 알려진 문제인 것 같습니다 . MTP 캐시는 전화기를 재부팅 할 때까지 오래됩니다.
해결 방법 입니다 :
- "미디어 저장소"앱의 데이터를 지 웁니다.
- 사용 SDrescan 또는 SD 스캐너 (도에, 안드로이드 4.4 / 5에 사용할 수 작동 F-이드 업데이 트를 강제로) 응용 프로그램을
또는 USB를 전혀 사용하지 마십시오. 이 문제는 파일에 액세스하는 다른 방법에 영향을주지 않습니다. 예를 들어 AirDroid 를 사용하여 파일을 전송하십시오.
참고 : Android 5.0.2에서는 작동하지 않습니다. "미디어 저장소"를 지우고 SD Rescanner를 사용하면 폴더가 Windows 7에서 열 수없는 4K 파일로 나타납니다. 이 시점에서 유일한 해결책은 미디어 저장소를 다시 한 번 지우고 장치를 다시 시작하는 것입니다.
파일을 닫은 후 다음 코드를 사용할 수 있습니다.
MediaScannerConnection.scanFile(this, new String[] { file.getAbsolutePath() }, null, null);
출처 : https://code.google.com/p/android/issues/detail?id=38282
이 문제에 몇 시간을 보낸 후 다음과 같이 해결했습니다.
private void rescanFolder(String dest) {
// Scan files only (not folders);
File[] files = new File(dest).listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isFile();
}
});
String[] paths = new String[files.length];
for (int co=0; co< files.length; co++)
paths[co] = files[co].getAbsolutePath();
MediaScannerConnection.scanFile(activity, paths, null, null);
// and now recursively scan subfolders
files = new File(dest).listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isDirectory();
}
});
for (int co=0; co<files.length; co++)
rescanFolder(files[co].getAbsolutePath());
}
문제는 파일 만 (폴더 아님) 스캔 한 다음 각 fubfolder에 대해 반복적으로 반복해야한다는 것입니다.
EDIT In addition, if you don't want pictures to be added to your photo album (but just your contents to appear over mtp protocol), remember to place an empty .nomedia
file in your folder before rescanning it, like this:
new File(myFolder + File.separator + ".nomedia").createNewFile();
rescanFolder(myFolder);
On Xperia Z below code worked just fine:
String screenShotFile = "....";
activity.sendBroadcast(new Intent(
Intent.ACTION_MEDIA_MOUNTED, Uri
.fromFile(screenShotFile)));
for 4.4+ use:
activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
Uri.fromFile(screenShotFile)));
(unfortunalelly I dont remember if I have tested it well enough)
http://commonsware.com/blog/2013/11/06/android-4p4-permission-regressions.html
notice /storage/emulated. Android 4.2 has some funky emulated per-app/user access stuff going on, for example a separate /sdcard/ for each user. Try moving the file to /sdcard/ instead of the emulated sdcard that is shown.
The simple code proposed to question How can I refresh MediaStore on Android? does the necessary update of MediaStore, if called after I put a file on external storage. Content on my Nexus 4 is refreshed instantly in Window 7 file explorer.
The best workaround I found to the bug mentioned in the accepted answer is to copy data from Android OS to a another machine/server (Linux, MacOS, windows) using SSH.
- Make sure that the device (Android) and the machine (where you want to copy the data) are reachable per IP or host name, for example by connecting them to the same wifi network.
Optional and recommended
- Connect the android device using USB tethering. This ensures fast speed because of the wired connection and guarantees that both IP addresses are visible to each other because both are in the same network.
In the Android device
- Install an SSH server. SSHelper worked like a charm
- Run the SSHelper and go to the configuration tab to get the IP address, port, and password. In the example below, they are 192.168.1.5, 2222 and 'admin'.
- The default password is admin but if you decide to change it hit the button "Restart server with new values" after changing it
In the machine
- Install rsync. If happen to use Ubuntu it is already installed by default.
- Open a shell and type the following command. Change the IP address and port to your values
rsync -avzhP --inplace --info=progress2 -e 'ssh -p 2222' 192.168.1.5:/storage/emulated/0/DCIM/Camera/ /home/username/path/to/pics/
- you will get the following prompt, enter your password
SSHelper Version 8.5 Copyright 2014, P. Lutus Default password is "admin" (recommend: change it) username@192.168.1.5's password: admin receiving incremental file list
The other suggestions did not work for me:
- Using USB storage mode instead of MTP is not supported by the device (as many other newer devices).
- There was no option in my OS (Android 6.0.1) to clear the "Media Storage" app data.
- Other methods of sharing files over the network had their draw backs. FTP does not ensure the files integrity. If the connection is dropped it either overwrites or skips all files, so one of the files might be incomplete. Other protocols might be hard to install and other apps might use proprietary protocols.
I needed to create a directory and copy some sample files for my app. After a lot of experiments and research the following procedure worked flawlessly for me:
1) Created directory using File.mkdir().
2) Copied files in directory and run MediaScanner on each file.
MediaScannerConnection.scanFile(context, new String[]{file.getAbsolutePath()}, null, null);
3) Run MediaScanner on directory.
MediaScannerConnection.scanFile(context, new String[]{directory.getAbsolutePath()}, null, null);
Result: The files and directory appear instantaneously on PC over MTP.
Had a similar issue with my OneplusOne:
After software update (to 6.0.1) i was not able to see my camera pictures when connecting to the computer (PTP and MTP). Both app's SDRescan and SDscanner had no effect.
My solution was to copy all pictures from DCIM to another folder using terminal or any file Explorer app on the Phone. When connecting to computer i was able to see the copied files.. i moved them to my computer and cleared my camera folder. No permanent solution but it fixed the problem for me at least until i do the next backup. =D
The above answers are fine for creating the file. If you later delete the file and want that change to be reflected as well, you can do one of the following; let's first cover two solutions that seem like they work, but will cause problems on some devices. The first one is to scan the deleted file:
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
This works on many devices for deleted files, but on some devices it'll actually cause a new 0-byte file to be created, which probably isn't what you want. In that case, if you're running on < 4.4 KitKat, you can do this:
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.fromFile(folder)));
Where folder is equal to file.getParentFile(). Unfortunately, on KitKat 4.4 and above, this will cause a SecurityException to get thrown, so for those devices, you can try deleting directly from the Media Store:
final Uri externalFilesUri = Files.getContentUri("external");
context.getContentResolver().delete(externalFilesUri, Files.FileColumns.DATA + "=?", new String[] {file.getAbsolutePath()});
나는 이것을 KitKat에서 작동하지 않는 ACTION_MEDIA_MOUNTED에 대한 해결 방법으로 테스트했으며 Nexus 5에서의 테스트에서 작동합니다.
최근에 동일한 문제에 직면했지만 몇 가지 추가 연구가 숨겨진 파일을 찾는 데 도움이되었습니다. Google이 저장 구조를 일부 변경 한 것 같습니다. 이 모든 파일은 다른 폴더로 이동되었습니다 This Computer\HTC One\Internal Storage\storage\emulated\0
. 그러나 모든 파일이 이동되지 않은 것이 이상합니다.
안드로이드 4.4.2
여기에 있는 설명서 에서 MediaScannerConnection.scanFile을 호출해야합니다.
// Tell the media scanner about the new file so that it is
// immediately available to the user.
MediaScannerConnection.scanFile(this,
new String[] { file.toString() }, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
참고 URL : https://stackoverflow.com/questions/13737261/nexus-4-not-showing-files-via-mtp
'Program Tip' 카테고리의 다른 글
애플리케이션 로더 : "전달을 진행할 수 없습니다. 기존 전송기 인스턴스가 현재이 패키지를 업로드하고 있습니다." (0) | 2020.10.15 |
---|---|
버튼을 클릭하면 열리는 새 브라우저 창으로 전환하는 방법은 무엇입니까? (0) | 2020.10.14 |
데이터 액세스 후 C #에서 Excel 응용 프로그램 프로세스 닫기 (0) | 2020.10.14 |
다른 함수 안에 함수를 정의 할 수없는 이유는 무엇입니까? (0) | 2020.10.14 |
C enum의 값 대신 텍스트 인쇄 (0) | 2020.10.14 |