本文介绍了无法看到Windows中的文件上SD卡写一个Android应用程序,除非我"强制关闭"该应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过我的Andr​​oid程序是这样写的文件

I wrote a file through my Android program like this:

String file = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Files/hello.txt";
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write(str+"\n");     \\yeah str has a value there
writer.close();

该计划,它的工作,它得到成品。现在,我打在Android上的后退按钮来关闭应用程序。会发生什么,现在是,如果我去到Android的文件浏览器(如天文)我可以看到该文件,但如果我安装在SD卡上的Windows,我看不到文件!

The program does its job and it gets finished. Now I hit the back button on Android to close the application. What happens now, is that if I go to Android file browser (like Astro) I can see the file but if I mount the SD card on Windows, I can't see the file!

现在,如果我去设置>应用>管理应用程序> 强制停机<应用> 我能看到的文件,即使在Windows

Now, if I go to Settings > Applications > Manage Applications > "Force Stop" <application> I'm able to see the file even in Windows.

我应该怎么做,这样我可以看到一个文件在Windows中,如果该文件写的是我的Andr​​oid应用程序在SD卡,我不想去设置,每一次接近打力。

What should I do so that I can see a file in Windows if the file is written by my android app on sd-card and I don't want to go to settings and hit force close every time.

其实,文件被正确写入(我认为),但由于Android的返回键默认行为不杀的应用程序,它看起来像,除非应用程序被打死,我不能开放的Andr​​oid以外的文件(在Android中,我仍然能看到它,甚至打开它)。

Actually the file is being written properly (I think) but since the default behaviour of Android 'back' button doesn't kill the app, and it looks like unless the app is killed I can't open the file outside Android (in Android, I'm still able to see it and even open it).

那么,什么将是这种情况下,最好的解决办法。我应该自动杀应用程序时,它正在关闭?人们说,System.exit()的严格不推荐使用。

So, what would be the best solution for this case. Should I automatically kill the app when it is closing? People say that System.exit() is strictly not recommended.

推荐答案

It's必要的,你使用下面的code,使您的存档将在Windows中的文件系统或在手机的画廊显示出来

It´s necessary that you use the following code so that your archive will be shown in the file system of windows or in the gallery of the phone.

您有两种可能:

  1. It's要快,因为只有Android的更新文件传递:

  1. It´s faster because android updates only the file passed:

MediaScannerConnection.scanFile(这一点,新的String [] {在这里你的路径&LT; /},NULL,NULL);

It's更昂贵,因为Android将搜索传递的路径中的所有文件。可以通过文件夹的唯一路径,以减少搜索文件:

It´s more expensive because android will search all the files in the path passed. You can pass only the path of the folder to reduce the search of the files:

context.sendBroadcast(新意图(Intent.ACTION_MEDIA_MOUNTED,乌里                .parse(文件://                        +的文件夹的路径)));

context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri .parse("file://" +"path of the folder")));

这篇关于无法看到Windows中的文件上SD卡写一个Android应用程序,除非我&QUOT;强制关闭&QUOT;该应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 12:25