Android的:替代pcated Context.MODE_WORLD_READABLE去$ P $? [英] Android: Alternative to the deprecated Context.MODE_WORLD_READABLE?

查看:3540
本文介绍了Android的:替代pcated Context.MODE_WORLD_READABLE去$ P $?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<一个href="http://stackoverflow.com/questions/7710486/android-how-do-i-save-a-file-that-is-readable-by-an-other-app">From这里我知道的方式写一个文件,并可以访问其他应用程序和其他的意图,但现在的Context.MODE_WORLD_READABLE是德precated我怎么能放心地做到这一点?

 的FileOutputStream OUT = myActivity.openFileOutput(fileTo,Context.MODE_WORLD_READABLE);
 

好详细信息:

我使用的是这样的:

 意图=新的意图(Intent.ACTION_VIEW);
intent.setDataAndType(URI,视频/ *);
 

和URI将是我会写一个SD卡的位置之一。而视频将来自应用程序,这样的问题是,如果现在不允许的,我怎么能写入文件,并查看它。

解决方案
  

和URI将是我会写一个SD卡的位置之一。

这已经是 MODE_WORLD_WRITABLE 默认情况下。另外请注意,您列出了code( openFileOutput())不会的没有的写入外部存储(你错误地称之为SD卡 )。 openFileOutput()是内部存储。

  

和视频将来自应用程序,这样的问题是,如果现在不允许的,我怎么能写入文件,并查看它。

如果你真的写文件到外部存储,只需要使用乌里指向该​​文件。

如果你正在写的文件导入到内部存储创建一个的ContentProvider 来服务于该文件,并使用乌里指向一个的ContentProvider 下面是一个示例应用程序的ContentProvider ,从提取PDF文件资产/ 第一次运行,然后通过中openFile担任了该文件()因此它可以通过一个PDF浏览器中查看。

From here I know a way to write a file and be accessible to other app and other intent, but now that the Context.MODE_WORLD_READABLE is deprecated how can I safely accomplish this?

FileOutputStream out = myActivity.openFileOutput(fileTo, Context.MODE_WORLD_READABLE);

Okay more info:

I'm using this:

intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "video/*");

And the uri will be the one that I will write to a sdcard location. And the video will come from the application so problem is, if this is now not allowed, how can I write the file and view it.

解决方案

And the uri will be the one that I will write to a sdcard location.

That is already MODE_WORLD_WRITABLE by default. Also note that the code you have listed (openFileOutput()) does not write to external storage (what you incorrectly call "sdcard"). openFileOutput() is for internal storage.

And the video will come from the application so problem is, if this is now not allowed, how can I write the file and view it.

If you are really writing the file to external storage, just use a Uri pointing to that file.

If you are writing the file to internal storage, create a ContentProvider to serve that file, and use a Uri pointing to that ContentProvider. Here is a sample application with a ContentProvider that extracts a PDF file from assets/ on first run, then serves up that file via openFile() so it can be viewed by a PDF viewer.

这篇关于Android的:替代pcated Context.MODE_WORLD_READABLE去$ P $?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆