我正在尝试简单地将一个简单的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();
}
}
Run Code Online (Sandbox Code Playgroud)
我可以使用Astro文件管理器在手机上看到该文件:
但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 …Run Code Online (Sandbox Code Playgroud) 因为我想确保MediaStore拥有最新信息而无需重新启动我想使用我在SO上找到的流行方式触发MediaScanner
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory())));
Run Code Online (Sandbox Code Playgroud)
这适用于我的三星S2 w/ICS,但不适用于我的Nexus 7 w/JellyBean.Logcat在我的Nexus 7上显示:
WARN/ActivityManager(480): Permission denied: checkComponentPermission() owningUid=10014
WARN/BroadcastQueue(480): Permission Denial: broadcasting Intent { act=android.intent.action.MEDIA_MOUNTED dat=file:///storage/emulated/0 flg=0x10 } from com.example.foo.bar (pid=17488, uid=10046) is not exported from uid 10014 due to receiver com.android.providers.downloads/.DownloadReceiver
INFO/ActivityManager(480): Start proc com.google.android.music:main for broadcast com.google.android.music/.store.MediaStoreImportService$Receiver: pid=17858 uid=10038 gids={50038, 3003, 1015, 1028}
INFO/MusicStore(17858): Database version: 50
INFO/MediaStoreImporter(17858): Update: incremental Added music: 0 Updated music: 0 Deleted music: 0 Created playlists: 0 Updated playlists: 0 Deleted playlists: 0 Inserted playlist …Run Code Online (Sandbox Code Playgroud) android android-intent android-mediascanner android-broadcast
我有一个应用程序需要在连接到流时收集大量数据。我需要将这些数据保存到一个文件中,稍后我可以将其从设备中取出并使用标准计算机进行分析。
我的代码目前如下所示:
private void saveData(byte[] data){
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File file = new File(path, "_Ascent_Test.txt");
try {
FileOutputStream stream = new FileOutputStream(file, true);
stream.write(data);
stream.close();
Log.i("saveData", "Data Saved");
} catch (IOException e) {
Log.e("SAVE DATA", "Could not write file " + e.getMessage());
}
}
Run Code Online (Sandbox Code Playgroud)
它正确地命中“数据已保存”日志,没有任何错误,但当我从计算机浏览该文件时,我无法在设备内部存储中的任何位置找到该文件。
我缺少什么?
谢谢。
编辑:我需要在 Nexus 7 上运行它