Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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:如果我想从Downloads文件夹中查看/选择一个SQLite数据库,那么mime类型是什么?全部内容,希望文章能够帮你解决Android:如果我想从Downloads文件夹中查看/选择一个SQLite数据库,那么mime类型是什么?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。