我想从位于/system/app/LALA 的 APK 加载服务。问题是,我收到以下错误,因为在 APP AndroidManifest 中,服务有 android:exported = false
。有什么方法可以加载吗?
Code
String packagePath = "other.app.package";
String apkName = null;
try {
apkName = getPackageManager().getApplicationInfo(packagePath, 0).sourceDir;
} catch (Exception e) {
e.printStackTrace();
}
PathClassLoader cLoader = new PathClassLoader(apkName, ClassLoader.getSystemClassLoader());
Context otherAppContext = createPackageContext(appPackage, CONTEXT_IGNORE_SECURITY | CONTEXT_INCLUDE_CODE);
String servicePath = packagePath + ".path.to.Service";
Class<?> Service = null;
try {
Service = Class.forName(servicePath, true, cLoader);
} catch (Exception e) {
e.printStackTrace();
}
otherAppContext.startService(new Intent(otherAppContext, Service));
Error
Caused by: java.lang.SecurityException: Not allowed to start service Intent { cmp=other.app.package/.path.to.Service } without permission not exported from uid X
[]的
最佳答案
Is there any way to load it?
不,对不起。如果服务不导出,则只能由自己的应用程序在内部使用。
关于android - 使用 android :exported=false 从 APK 加载服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17095225/