在 Jelly Bean 上访问其他 Android 应用的资产 [英] Accessing assets of other Android app on Jelly Bean

查看:23
本文介绍了在 Jelly Bean 上访问其他 Android 应用的资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个 Android 应用程序.一个是免费的阅读器"应用,另一个是付费的数据"应用,其资产子目录中有一个文本文件.

I have a pair of Android apps. One is a free 'reader' app and the other is a paid for 'Data' app with a text file in a sub directory of its assets.

阅读器应用使用以下代码访问数据应用的文本文件:

The reader app uses the following code to access the data app's text file:

Intent myIntent = new Intent("myintent");
List<ResolveInfo> dataPacks = packageManager.queryIntentActivities(myIntent, 0);
String packageName = dataPacks.get(0).activityInfo.packageName
Resources res = packageManager.getResourcesForApplication(packageName);
AssetManager assets = res.getAssets();
String[] dataFiles = assets.list("Data");

这一直运行良好,但使用 Google Play 下载到 Jelly Bean 的应用程序无法运行(数据文件为空).如果该应用程序是直接从电子邮件安装的,那很好,所以我怀疑我的问题与 Google Play 最近的安全更改有关.但是,据称这些已被撤消,但我仍然遇到问题.

This has been working fine but apps downloaded to Jelly Bean using Google Play are not working (datafiles is empty). If the app is installed directly from email it is fine so I suspect my problem is related to the recent security changes to Google Play. However, these have allegedly been undone but I am still having problems.

任何人都可以阐明出了什么问题吗?(可惜我没有果冻豆设备)

Can anybody shed light on what is going wrong? (unfortunately I dont have a Jelly Bean device)

或者,有人可以建议一种更好的机制来访问数据应用的 txt 文件吗?

Alternatively, can somebody suggest a better mechanism for accessing the data app's txt file?

谢谢

推荐答案

JB 设备上的付费应用程序被前向锁定".这意味着 APK 分为两部分 - 一部分是公共资源,另一部分是私有资源和代码,其他应用程序无法读取.这里有一些细节:http://nelenkov.blogspot.com/2012/07/using-app-encryption-in-jelly-bean.html

Paid apps on JB devices are 'forward locked'. This means that the APK is split in two parts -- one with public resources, and one with private ones and code, which is not readable by other apps. Some details here: http://nelenkov.blogspot.com/2012/07/using-app-encryption-in-jelly-bean.html

我没有详细研究文件是如何拆分的,但您看到的问题表明资产是私有 APK 的一部分,这是有道理的,因为您通常将 API 密钥等粘贴在资产中.

I haven't looked into how files are split in detail, but the problem you are seeing suggests that assets are part of the private APK, which makes sense, since you typically stick API keys, etc in assets.

因此,您需要使用更间接的方法在两个应用程序之间共享信息,例如 ContentProvider 或远程服务.确保您需要签名权限才能访问它们,以确保只有您自己的应用程序可以使用它们.

So you need to use a more indirect method to share info between the two apps such as a ContentProvider or remote service. Make sure you require signature permissions to access those, to make sure only your own apps can use them.

这篇关于在 Jelly Bean 上访问其他 Android 应用的资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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