- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有来自 this
的代码统一回答代码以安装 apk,但它在 Android 7.0 中不起作用,因为不再支持 Uri.fromfile
并且现在应该使用 FileProvider.getUriForFile
。
我尝试在 android studio 中打开项目并按照本教程操作 list 文件 - https://inthecheesefactory.com/blog/how-to-share-access-to-file-with-fileprovider-on-android-nougat/en
AndroidJavaClass intentObj = new
AndroidJavaClass("android.content.Intent");
string ACTION_VIEW = intentObj.GetStatic<string>("ACTION_VIEW");
int FLAG_ACTIVITY_NEW_TASK = intentObj.GetStatic<int>
("FLAG_ACTIVITY_NEW_TASK");
AndroidJavaObject intent = new
AndroidJavaObject("android.content.Intent", ACTION_VIEW);
AndroidJavaObject fileObj = new AndroidJavaObject("java.io.File",
apkPath);
AndroidJavaClass uriObj = new AndroidJavaClass("android.net.Uri");
AndroidJavaObject uri = uriObj.CallStatic<AndroidJavaObject>
("fromFile", fileObj);
intent.Call<AndroidJavaObject>("setDataAndType", uri,
"application/vnd.android.package-archive");
intent.Call<AndroidJavaObject>("addFlags", FLAG_ACTIVITY_NEW_TASK);
intent.Call<AndroidJavaObject>("setClassName",
"com.android.packageinstaller",
"com.android.packageinstaller.PackageInstallerActivity");
AndroidJavaClass unityPlayer = new
AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity =
unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
currentActivity.Call("startActivity", intent);
最佳答案
只是替换
AndroidJavaObject fileObj = new AndroidJavaObject("java.io.File", apkPath);
AndroidJavaClass uriObj = new AndroidJavaClass("android.net.Uri");
AndroidJavaObject uri = uriObj.CallStatic<AndroidJavaObject>("fromFile", fileObj);
与
AndroidJavaObject fileObj = new AndroidJavaObject("java.io.File", apkPath);
AndroidJavaClass fileProvider = new AndroidJavaClass("android.support.v4.content.FileProvider");
AndroidJavaObject uri = fileProvider.CallStatic<AndroidJavaObject>("getUriForFile", unityContext, authority, fileObj);
authority
参数构造为:
string packageName = unityContext.Call<string>("getPackageName");
string authority = packageName + ".fileprovider";
然后在调用 currentActivity.Call
函数之前向 Intent 添加 FLAG_GRANT_READ_URI_PERMISSION
权限。
intent.Call<AndroidJavaObject>("addFlags", FLAG_GRANT_READ_URI_PERMISSION);
有关完整脚本,请参阅现在编辑的 How to install Android apk from unity application问题。
关于c# - 如何在 Unity 中将 Uri.fromfile 转换为 FileProvider.getUriForFile?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45051350/
我不明白为什么有两段代码要做完全相同的事情,却在 Scala 中做不同的事情。 第一个例子: scala> val ggg = Source.fromFile("/somefile"); ggg: s
我想创建一个 Windows 窗体,它从文件中获取图像并显示在 C# 的 pictureBox 中当我在“=”之后键入 image.FromFile 时遇到问题,FromFile 变成红色下划线,就好
我使用 Image.FromFile() 读取用户上传的图像文件。对于“选择文件”对话框,我可以允许哪些文件扩展名? 谢谢! 最佳答案 来自微软的文档:http://msdn.microsoft.co
我想知道以下代码片段的效率是多少: val lst = Source.fromFile(f).getLines.toList 发出lst.contains(x)时, 这是否意味着f正在被重新扫描,或者
我可能想在这里重新发明轮子,但是 numpy 有一个 fromfile() 函数,可以读取 - 我想 - CSV 文件。 它的速度似乎令人难以置信 - 即使与 Pandas read_csv() 相比
我正在尝试更新一些在方法中使用 np.fromfile 的旧代码。当我尝试在 numpy 源中搜索此方法时,我只找到 np.core.records.fromfile ,但是当您搜索文档时,您可以找到
我正在尝试向 numpy.fromfile 传递一个模拟的 file,但我不断收到以下错误: IOError: !first argument must be an open file 这是一个基本示
np.fromfile() 是否有最大文件大小?我正在尝试读取一个 48GB 的文件,其中包含大约 2.1e9 条记录(每条记录有 5 个值)。 当我将计数限制为 8e7 时它起作用了: from
我正在尝试使用 numpy.fromfile阅读structured array (文件头)通过传入 user defined data-type .出于某种原因,我的结构化数组元素以二维数组而不是平
这个问题可能是微不足道的,但我真的不知道如何解决它。假设我使用 np.int64 类型生成一个大小为 (4,3) 的 numpy 数组,然后写入二进制文件。该数组如下所示: [[ 1 2 3]
我有一个带有 xfce 窗口管理器的系统 fedora 15。 我安装了一个 inotify 工具来玩。 我想控制我的文件在我的工作过程中会发生什么。我今天使用一个命令来运行 inotify inot
我有一些大文件(甚至压缩到 10GB 左右),其中包含一个 ASCII header ,然后原则上每个大约 3MB 的 numpy.recarrays,我们称它们为“事件”。我的第一种方法是这样的:
为什么我会遇到内存不足的错误?谢谢 if (File.Exists(photoURI)) { FileStream fs = new FileStream(photoURI, FileMode
我有一个二进制文件,其中包含飞机位置的记录。每条记录如下所示: 0x00: Time, float32 0x04: X, float32 // X axis position 0x08: Y, flo
我写的文件传输代码如下: val fileContent: Enumerator[Array[Byte]] = Enumerator.fromFile(file) val size = file.le
全部, 我有一个只有 ~120MB 的 CSV 文件(将其命名为 demo.csv) 以下代码会导致堆从正常大小的 100MB 膨胀到 1.7GB,尽管加载的底层数据只有 120MB 我可以在哪些方面
我在这种情况下使用 Image.FromFile(string) 方法: using System; using System.Collections.Generic; using System.Co
它和我想象的一样奇怪。 o.0. 我已经检查并仔细检查了,甚至不明白为什么它不起作用... 下面是使用的代码: try { if (!(Directory.Exists(@"C:\Simple
我发现了几个类似的问题,但没有一个能准确描述我面临的问题。我有一个 OBJ 文件,其中包含描述顶点位置的行: v 0.01214 0.4242 0.82874 我想将此数据转换为 matlab 友好的
我正在使用 numpy.fromfile 构建一个数组,我可以将其传递给 pandas.DataFrame 构造函数 import numpy as np import pandas as pd de
我是一名优秀的程序员,十分优秀!