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包实现,邀请码自动填充

相关推荐
Kotlin上海用户组34 分钟前
Koin vs. Hilt——最流行的 Android DI 框架全方位对比
android·架构·kotlin
zzq19961 小时前
Android framework 开发者模式下,如何修改动画过度模式
android
木叶丸1 小时前
Flutter 生命周期完全指南
android·flutter·ios
阿幸软件杂货间1 小时前
阿幸课堂随机点名
android·开发语言·javascript
没有了遇见1 小时前
Android 渐变色整理之功能实现<二>文字,背景,边框,进度条等
android
没有了遇见2 小时前
Android RecycleView 条目进入和滑出屏幕的渐变阴影效果
android
站在巨人肩膀上的码农3 小时前
去掉长按遥控器power键后提示关机、飞行模式的弹窗
android·安卓·rk·关机弹窗·power键·长按·飞行模式弹窗
呼啦啦--隔壁老王3 小时前
屏幕旋转流程
android
人生何处不修行4 小时前
实战:Android 15 (API 35) 适配 & 构建踩坑全记录
android
用户2018792831674 小时前
gralde的《依赖契约法典》
android