背景
我制作了一个业余时间应用程序(),它的主要功能之一是安装 APK 文件。
问题
安装应用程序的用户希望启动器上会出现新的应用程序图标。
这可能会在 Play 商店中发生,但由于某种原因启动器会忽略其他类型的安装。
Play 商店安装应用程序的方式与第三方应用程序的安装方式有所不同。
我想知道如何正确执行此操作,例如在 Play 商店上,以便安装 APK 文件也会创建应用程序图标。
我尝试过的
我发现安装 APK 的唯一方法是:
@Nullable
public static Intent prepareAppInstallationIntent(Context context, File file, final boolean requestResult) {
Intent intent = null;
try {
intent = new Intent(Intent.ACTION_INSTALL_PACKAGE)//
.setDataAndType(
VERSION.SDK_INT >= VERSION_CODES.N ?
android.support.v4.content.FileProvider.getUriForFile(context, context.getPackageName() + ".provider", file)
: Uri.fromFile(file),
"application/vnd.android.package-archive")
.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true)
.putExtra(Intent.EXTRA_RETURN_RESULT, requestResult)
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (VERSION.SDK_INT < VERSION_CODES.JELLY_BEAN)
intent.putExtra(Intent.EXTRA_ALLOW_REPLACE, true);
} catch (Throwable e) {
}
return intent;
}
manifest
<provider
android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/>
</provider>
xml/provider_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<!--<external-path name="external_files" path="."/>-->
<external-path
name="files_root" path="Android/data/${applicationId}"/>
<external-path
name="external_storage_root" path="."/>
</paths>
但这不会在启动器上创建应用程序图标。
在问题跟踪器上写下这一点(here https://issuetracker.google.com/issues/80464229#comment5),我知道了我应该做什么。我获悉:
如果应用程序是通过新安装的,图标会添加到主屏幕
PackageInstaller API(并提供正确的安装原因)。
安装类似命令的应用程序不支持此功能。
问题
是否有第三方应用程序可以正确安装应用程序的 API,并在启动器上有一个新的图标?如果是这样,具体是怎样的?
有没有办法甚至使用 root 来做到这一点?并通过PC使用adb命令?