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

相关推荐
许三多20203 小时前
Android studio Could not move temporary workspace
android·ide·android studio·workspace
王江奎4 小时前
FFmpeg中使用Android Content协议打开文件设备
android·ffmpeg
清霜之辰4 小时前
安卓开发用到的设计模式(1)创建型模式
android·设计模式·创建型模式
隐-梵4 小时前
面向GIS的Android studio移动开发(二)--在地图上绘制电子围栏
android·ide·android studio
末央&5 小时前
【Linux】进程状态
android·linux·运维
luyou1126 小时前
雷电模拟器去除广告绿色版电脑安卓模拟器 电脑上使用安卓系统软件游戏 v9.1.45.1
android·游戏·电脑
楠目6 小时前
网络安全--PHP第一天
android·web安全·php
追随远方7 小时前
网络框架二次封装:基于Kotlin的高扩展性网络请求框架完整实现
android·网络·okhttp·kotlin
元亓亓亓8 小时前
MySQL--day5--多表查询
android·数据库·mysql
androidwork19 小时前
Kotlin与机器学习实战:Android端集成TensorFlow Lite全指南
android·机器学习·kotlin·tensorflow