Android如何将第三方预装的AP安装在data/app下面,用户可以选择卸载,但是在用户恢复出厂设置后,会再次自动安装

大体思路是,将第三方应用保存在system/media/app目录下,在用户第一次启动手机或者恢复出厂设置的时候将这些apk文件拷贝到/data/app目录下面,PackageManagerService在系统启动的时候会自动扫描data/app目录下面的文件,然后自动安装。

具体步骤如下:

第一步,新加一个文件preinstall.txt来判断用户是在烧写手机和恢复出厂设置后第一次启动手机,还是用户正常重启手机。如果该文件在data/app目录存在,则是用户正常重启手机,否则就是用户恢复出厂设置或者第一次刷机后开机,这时就需要自动安装预装程序。注意此文件内容一定不能为空,否则shell脚本-s会认为该文件不存在

第二步,在system/core/rootdir/etc目录下新建shell脚本文件,如init.qcom.preinstall.sh,内容如下:

#!/system/bin/sh
# Copyright (c) 2009-2012, Code Aurora Forum. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the distribution.
#     * Neither the name of Code Aurora nor
#       the names of its contributors may be used to endorse or promote
#       products derived from this software without specific prior written
#       permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
#
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值