Android 分享页面下载app后 自动填充邀请码

android 分享出去h5页面,通过页面下载对应包,安装启动登录注册时候,需要自动填写邀请码,一般情况下,我们需要将分享人信息写入app包中,这样下载时候根据这个信息可以获取到对应安装包。

android我们可以把信息写入assets文件夹下,打包时候assets不会被编译。所以在app安装后,只需要读取对应assets文件,获取对应邀请码。

复制代码
 /**
     * 获取本地写入邀请码文件内容
     *
     * @param context
     * @return
     */
 public static String popularizeInvitationCode(Context context) {
        String invitationCode = null;
        AssetManager assetManager = null;
        InputStream inputStream = null;
        BufferedReader bufferedReader = null;
        try {
            if (context != null) {
                assetManager = context.getAssets();
                if (assetManager != null) {
                    inputStream = assetManager.open("popularize-invitation-code.properties");
                    if (inputStream != null) {
                        bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                        StringBuffer stringBuffer = new StringBuffer();
                        while (null != (invitationCode = bufferedReader.readLine())) {
                            stringBuffer.append(invitationCode);
                        }
                        return stringBuffer.toString();
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
            //由于assetManager 只直接获取系统资源对应,不是自己new出来。所以不能close,
            //关闭会导致系统资源关闭,无法加载,引发资源找不到异常。
            //    if (assetManager != null){
            //        assetManager.close();
            //    }
                if (inputStream != null) {
                    inputStream.close();
                }
                if (bufferedReader != null) {
                    bufferedReader.close();
                }

            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return invitationCode;
    }

重点:assetManager在open之后千万不要关闭 //assetManager.close();

当用户点击邀请时候,我们告诉后台生成对应app包。被邀请用户点击下载时候,下载指定app包实现,邀请码自动填充

相关推荐
用户69371750013841 分钟前
Android 手机终于能当电脑用了
android·前端
用户51722315748032 分钟前
android资源类型与布局资源详细介绍
android
优选资源分享1 小时前
GKD v1.11.6 | 安卓开屏广告跳过工具 可用版
android
robotx1 小时前
安卓zygote启动相关
android
Mac的实验室2 小时前
2026年最新真实社交怎么注册?手把手教你如何成功注册Truth Social账号
android
毕设源码-郭学长3 小时前
【开题答辩全过程】以 基于Android的点餐APP的设计为例,包含答辩的问题和答案
android
polaris06303 小时前
学生成绩管理系统(MySQL)
android·数据库·mysql
__Yvan3 小时前
Kotlin 的 ?.let{} ?: run{} 真的等价于 if-else 吗?
android·开发语言·前端·kotlin
tangweiguo030519874 小时前
Android WorkManager 完整实战教程(含完整文件)
android·kotlin
loitawu4 小时前
Rockchip Android16 系统裁剪指南
android·android16·android裁剪·系统裁剪·rockchip app