Android 在其他应用程序中打开文件和文件夹
我得到了一个包含文件路径(mime类型未知)的活动。 我有两个钮扣。应该在用户选择的文件管理器中打开文件夹。 另一个应该在适合该文件类型的应用程序中打开该文件。 点击按钮工作。openFolder让我选择一个文件管理器:使用androzip或根资源管理器将我带到sdcard,但astro希望我选择一个文件,就像我将文件上载到oneclickhoster一样。OpenFile没有给我选择,但打开了一个十六进制编辑器,不幸的是,我说这个文件是“空的” 编辑:打开文件的问题是Intent.ACTION\u编辑,它应该是Intent.ACTION\u视图。Android 在其他应用程序中打开文件和文件夹,android,Android,我得到了一个包含文件路径(mime类型未知)的活动。 我有两个钮扣。应该在用户选择的文件管理器中打开文件夹。 另一个应该在适合该文件类型的应用程序中打开该文件。 点击按钮工作。openFolder让我选择一个文件管理器:使用androzip或根资源管理器将我带到sdcard,但astro希望我选择一个文件,就像我将文件上载到oneclickhoster一样。OpenFile没有给我选择,但打开了一个十六进制编辑器,不幸的是,我说这个文件是“空的” 编辑:打开文件的问题是Intent.ACTION
但我仍然不知道如何打开文件夹。“它不工作”没有给我们提供任何信息。好的,我更新了帖子。。。也许这会有帮助!
public void openFolder(View v)
{
File f=new File(path);
if(f.exists())
{
String folder=f.getAbsolutePath().replace("/"+f.getName(),"")+"/";
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(folder);
intent.setDataAndType(uri, "file/*");
startActivity(Intent.createChooser(intent, "Open folder"));
}
}
public void openFile(View v)
{
File f=new File(path);
if(f.exists())
{
//example for path: path=/storage/sdcard0/test.mp3
Intent intent = new Intent(Intent.ACTION_EDIT);
Uri uri = Uri.parse("file:/"+path);
intent.setDataAndType(uri, getMIME());
startActivity(Intent.createChooser(intent, "Open file"));
}
}
private String getMIME()
{
String type =null;
String extension = MimeTypeMap.getFileExtensionFromUrl(path);
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
}
if(type.equals("") || type == null)
return "UNKNOWN";
else
return type;
}