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

相关推荐
冬奇Lab18 分钟前
硬件加速与 OMX/Codec2:解密编解码器的底层世界
android·音视频开发·视频编码
亘元有量-流量变现34 分钟前
ASO优化全流程实操指南:从基础到迭代,精准提升App曝光与转化
android·ios·harmonyos·aso优化·方糖试玩
私人珍藏库1 小时前
【Android】GameNative 0.9.0 [特殊字符] 手机畅玩Steam游戏
android·游戏·智能手机·app·工具·软件·多功能
诸神黄昏EX1 小时前
Android Safety 系列专题【篇七:Android AVF机制】
android
Fᴏʀ ʏ꯭ᴏ꯭ᴜ꯭.2 小时前
MySQL 主从架构中的使用技巧及优化
android·mysql·架构
羊小蜜.2 小时前
Mysql 11: 存储过程全解——从创建到使用
android·数据库·mysql·存储过程
zh_xuan2 小时前
Android compose和传统view混用
android
大黄说说2 小时前
MySQL索引失效的常见场景有哪些?如何通过EXPLAIN分析查询性能?
android·adb
冰糖葫芦三剑客2 小时前
华为 Android APP 应用内生成合成内容的文件元数据中添加隐式标识的截图 开发要怎么生成?
android·华为
羊小蜜.2 小时前
Mysql 12: 视图全解——从创建到使用
android·数据库·mysql·视图