android获取友盟渠道名,补充3个注意点
来源:互联网 发布:天宝软件 编辑:程序博客网 时间:2024/05/24 04:27
实现做批量打包之后,区分版本就不用靠在代码里写常量的方法来实现了,可以通过渠道名称来区分版本并以此作为参数上传给服务器
批量开发就不讲了,一般搜搜都有
一般获取渠道名称的通用方法:
/** * 获取application中指定的meta-data * @return 如果没有获取成功(没有对应值,或者异常),则返回值为空 */ public static String getAppMetaData(Context ctx, String key) { if (ctx == null || TextUtils.isEmpty(key)) { return null; } String resultData = null; try { PackageManager packageManager = ctx.getPackageManager(); if (packageManager != null) { ApplicationInfo applicationInfo = packageManager.getApplicationInfo(ctx.getPackageName(), PackageManager.GET_META_DATA); if (applicationInfo != null) { if (applicationInfo.metaData != null) { resultData = applicationInfo.metaData.getString(key); } } } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return resultData; }
这里要补充说明3点:
1.从上面的代码里可以看到,获取信息是从applicationinfo里面获取的,所以批量开发要写的meta-data是要写到manifest的application里面的
2.获取渠道名称需要的参数key,是meta-data里的name
3.也是很重要的一点,一般批量打包里需要在buildtypes里定义打出来的包的命名规范,这是网上找的一种方法:
// 自定义输出配置applicationVariants.all { variant -> variant.outputs.each { output -> def outputFile = output.outputFile if (outputFile != null && outputFile.name.endsWith('.apk')) { // 输出apk名称为haibao_v1.0_wandoujia.apk def fileName = "haibao_v${defaultConfig.versionName}_${variant.productFlavors[0].name}.apk" output.outputFile = new File(outputFile.parent, fileName) } }}
但是我测出来结果,用这种方法单独打的渠道包的安装包大小正常,可以安装,但是批量打包出来的APK体积要小一些,并且安装失败
由于具体原因暂时找不到,我使用了另外一种方法:
//系统默认命名,release是签名版本,release-unsigned是未签名版本signingConfig signingConfigs.release
这种方法批量打包打的渠道包的APK大小正常,可以安装
贴一下buildtypes的完整代码
buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' //系统默认命名,release是签名版本,release-unsigned是未签名版本 signingConfig signingConfigs.release// // 自定义输出配置// applicationVariants.all { variant ->// variant.outputs.each { output ->// def outputFile = output.outputFile// if (outputFile != null && outputFile.name.endsWith('.apk')) {// // 输出apk名称为haibao_v1.0_wandoujia.apk// def fileName = "haibao_v${defaultConfig.versionName}_${variant.productFlavors[0].name}.apk"// output.outputFile = new File(outputFile.parent, fileName)// }// }// } }
2 0
- android获取友盟渠道名,补充3个注意点
- android获取友盟渠道名
- android:获取渠道名
- android获取友盟渠道名以及获取application中的meta-data
- android获取友盟渠道名以及获取application中的meta-data
- android获取友盟渠道名以及获取application中的meta-data
- 友盟多渠道获取渠道名 附赠多渠道打包文件
- Android获取友盟统计渠道名称
- 获取渠道名
- 代码获取渠道名
- Android ant自动打包脚本:自动替换友盟渠道、版本号、包名
- Android ant 自动打包脚本:自动替换友盟渠道、版本号、包名
- Android ant自动打包脚本:自动替换友盟渠道、版本号、包名
- Android ant自动打包脚本:自动替换友盟渠道、版本号、包名
- 安卓获取渠道名渠道id Android获取设备唯一标识的终极解决方法,防止安卓7.0时崩溃问题
- springboot番外之注意点补充
- Android 如何获取 umeng 的 渠道信息
- c语言中的数组名注意点
- 如何用Perl向MySQL中插入数据
- H.264视频压缩标准
- PhET开发概述
- 第十周回文数(1)
- Forbidden You don't have permission to access /phpmyadmin/ on this server 解决办法
- android获取友盟渠道名,补充3个注意点
- 面向对象的三大基本特性
- iOS10语音识别框架SpeechFramework应用
- 浅读——reducing the dimensionality of data with neural networks(一)
- PHP关于大图片上传的相关配置
- 计算个人税
- Redis简介和Linux环境下的安装
- 好用插件
- 编译器与集成开发环境