android 第三方 实现静默安装软件,Android三方应用实现静默安装

背景

一个三方应用想要内置进我们 ROM,并且想要能够静默安装应用。

App的静默安装和卸载

Android系统本身提供了安装卸载功能,但是api接口是@hide的,不是公开的接口,所以在应用级别

是无法实现静默安装和卸载的,要实现静默安装和卸载需要是系统应用,要有系统签名和相应的权限。

思路1

通过反射获得安装接口installPackage和 卸载接口 deletePackage

在自己的包中引入两个接口IPackageInstallObserver和IPackageDeleteObserver的空实现

调用安装卸载的方法,回调上面的两个接口

添加权限

进行系统签名

将应用push到系统中,作为系统应用

在PackageManager中的提供的接口如下:

/**

* @deprecated replaced by {@link PackageInstaller}

* @hide

*/

@Deprecated

public abstract void installPackage(

Uri packageURI,

PackageInstallObserver observer,

@InstallFlags int flags,

String installerPackageName);

/**

* Attempts to delete a package. Since this may take a little while, the

* result will be posted back to the given observer. A deletion will fail if

* the calling context lacks the

* {@link android.Manifest.permission#DELETE_PACKAGES} permission, if the

* named package cannot be found, or if the named package is a system

* package.

*

* @param packageName The name of the package to delete

* @param observer An observer callback to get notified when the package

* deletion is complete.

* {@link android.content.pm.IPackageDeleteObserver#packageDeleted}

* will be called when that happens. observer may be null to

* indicate that no callback is desired.

* @hide

*/

@RequiresPermission(Manifest.permission.DELETE_PACKAGES)

public abstract void deletePackage(String packageName, IPackageDeleteObserver observer,

@DeleteFlags int flags);

引入两个回掉的空实现

在自己应用的工程中新建一个包android.content.pm,并添加两个文件

IPackageDeleteObserver.java

package android.content.pm;

public interface IPackageDeleteObserver extends android.os.IInterface {

public abstract static class Stub extends android.os.Binder implements android.content.pm.IPackageDeleteObserver {

public Stub() {

throw new RuntimeException("Stub!");

}

public static android.content.pm.IPackageDeleteObserver asInterface(android.os.IBinder obj) {

throw new RuntimeException("Stub!");

}

public android.os.IBinder asBinder() {

throw new RuntimeException("Stub!");

}

public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags)

throws android.os.RemoteException {

throw new RuntimeException("Stub!");

}

}

public abstract void packageDeleted(java.lang.String packageName, int returnCode)

throws android.os.RemoteException;

}

IPackageInstallObserver.java

package android.content.pm;

public interface IPackageInstallObserver extends android.os.IInterface {

public abstract static class Stub extends android.os.Binder implements android.content.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值