Android:如果我想从Downloads文件夹中查看/选择一个SQLite数据库,那么mime类型是什么?

我正在使用sqlite数据库编写应用程序.我已经编写了备份我的sqlite数据库代码.我现在希望能够从这样的副本中恢复我的应用程序数据库.我正在使用 Android设备“打开”对话框.如果我在列表中使用其他内容提供商,我会看到该文件,例如“蓝牙文件传输”!但是如果我尝试使用“下载”选项,我就不会看到它.

我在我的下载文件夹中复制了一个sqlite数据库.我试图使用fileIntent.setType(“/”).

谢谢.

解决方法

它是application / x-sqlite3.我在自己的应用程序中使用它.

More info here.

这是我如何使用它的一个例子:

File backupDB = ...;

//Uri uri = Uri.fromFile(backupDB); //From Android 7,this line results in a FileUriExposedException. Therefore,we must use MyFileProvider instead...
Uri uri = FileProvider.getUriForFile(this,getApplicationContext().getPackageName() + ".com.example.myapp.myfileprovider",backupDB);

Intent newIntent = new Intent(Intent.ACTION_VIEW);
newIntent.setDataAndType(uri,"application/x-sqlite3");
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
newIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

startActivity(newIntent);

为了完整性,这是我的MyFileProvider.java类

package com.example.myapp;

import android.support.v4.content.FileProvider;

public class MyFileProvider extends FileProvider {
}

以下是如何在清单中声明它:

<provider
    android:name=".MyFileProvider"
    android:authorities="${applicationId}.com.example.myapp.myfileprovider"
    android:exported="false"
    android:grantUriPermissions="true">
    <Meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/my_file_provider_paths"/>
</provider>

最后,这是我的my_file_provider_paths.xml:

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-path name="external_files" path="."/>
</paths>

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...