import ‘package:permission_handler/permission_handler.dart’;
/// 检查是否有权限,用于安卓
Future checkPermission() async {
if (_flatform == ‘android’) {
PermissionStatus permission = await PermissionHandler()
.checkPermissionStatus(PermissionGroup.storage);
if (permission != PermissionStatus.granted) {
Map<PermissionGroup, PermissionStatus> permissions =
await PermissionHandler()
.requestPermissions([PermissionGroup.storage]);
if (permissions[PermissionGroup.storage] == PermissionStatus.granted) {
return true;
}
} else {
return true;
}
} else {
return true;
}
return false;
}
需要在Android的 AndroidManifest.xml文件增加权限配置
下载apk根据返回的下载链接,需要先把Android包文件下载到本地,这里需要对文件流进行操作,下载工具我是采用的HTTP请求工具库dio,这里也可以采用专业的下载插件flutter_downloader,这个插件支持Android、IOS下载,但是配置起来复杂,我折腾了好长时间,也没能配置成功,有玩转这个插件的可以给我推荐些文章。
import ‘package:dio/dio.dart’;
import ‘package:path_provider/path_provider.dart’;
/// 下载安卓更新包
Future downloadAndroid(String url) async {
/// 创建存储文件
Directory storageDir = await getExternalStorageDirectory();
String storagePath = storageDir.path;
File file = new File(‘
s
t
o
r
a
g
e
P
a
t
h
/
storagePath/
storagePath/{Config.APP_NAME}v${_version}.apk’);
if (!file.existsSync()) {
file.createSync();
}
try {
/// 发起下载请求
Response response = await Dio().get(url,
onReceiveProgress: showDownloadProgress,
options: Options(
responseType: ResponseType.bytes,
followRedirects: false,
));
file.writeAsBytesSync(response.data);
return file;
} catch (e) {
print(e);
}
}
安装apk
import ‘package:install_plugin/install_plugin.dart’;
/// 安装apk
Future installApk(String url) async {
File _apkFile = await downloadAndroid(url);
String _apkFilePath = _apkFile.path;
if (_apkFilePath.isEmpty) {
print(‘make sure the apk file is set’);
return;
}
InstallPlugin.installApk(_apkFilePath, Config.APP_ID)
.then((result) {
print(‘install apk $result’);
}).catchError((error) {
print(‘install apk error: $error’);
});
}
这里我用的是install_plugin: ^2.0.1
,该插件在安卓上能正常运行,但是在Apple上先是报
[!] Unable to determine Swift version for the following pods:
install_plugin does not specify a Swift version and none of the targets (Runner) integrating it have the SWIFT_VERSION attribute set. Please contact the author or set the SWIFT_VERSION attribute in at least one of the targets that integrate this pod.
Xcode:
The sandbox is not in sync with the Podfile.lock. Run ‘pod install’ or update your CocoaPods installation.
手动添加了SWIFT_VERSION
后,又报
fatal error: ‘install_plugin/install_plugin-Swift.h’ file not found
#import <install_plugin/install_plugin-Swift.h>
报错原因是iOS在构建的时候默认是objective-c,而这个插件使用的是swift
解决方法:
创建ios/File.swift
//
// File.swift
// Runner
//
// Created by richer on 2019/11/22.
// Copyright © 2019 The Chromium Authors. All rights reserved.
//
import Foundation
创建ios/Runner-Bridging-Header.h文件
//
// Use this file to import your target’s public headers that you would like to expose to Swift.
//
编辑ios/Podfile,在target ‘Runner’ do后面添加 use_frameworks!
target ‘Runner’ do
use_frameworks!
- 展示下载进度,dio提供下载进度的回调
/// 展示下载进度
void showDownloadProgress(num received, num total) {
if (total != -1) {
double _progress =
double.parse(‘${(received / total).toStringAsFixed(2)}’);
eventManager.eventBus
.fire(new UpdateAndroidProgressEvent(_progress));
}
}
最后
简历首选内推方式,速度快,效率高啊!然后可以在拉钩,boss,脉脉,大街上看看。简历上写道熟悉什么技术就一定要去熟悉它,不然被问到不会很尴尬!做过什么项目,即使项目体量不大,但也一定要熟悉实现原理!不是你负责的部分,也可以看看同事是怎么实现的,换你来做你会怎么做?做过什么,会什么是广度问题,取决于项目内容。但做过什么,达到怎样一个境界,这是深度问题,和个人学习能力和解决问题的态度有关了。大公司看深度,小公司看广度。大公司面试你会的,小公司面试他们用到的你会不会,也就是岗位匹配度。
面试过程一定要有礼貌!即使你觉得面试官不尊重你,经常打断你的讲解,或者你觉得他不如你,问的问题缺乏专业水平,你也一定要尊重他,谁叫现在是他选择你,等你拿到offer后就是你选择他了。
另外,描述问题一定要慢!不要一下子讲一大堆,慢显得你沉稳、自信,而且你还有时间反应思路接下来怎么讲更好。现在开发过多依赖ide,所以会有个弊端,当我们在面试讲解很容易不知道某个方法怎么读,这是一个硬伤…所以一定要对常见的关键性的类名、方法名、关键字读准,有些面试官不耐烦会说“你到底说的是哪个?”这时我们会容易乱了阵脚。正确的发音+沉稳的描述+好听的嗓音决对是一个加分项!
最重要的是心态!心态!心态!重要事情说三遍!面试时间很短,在短时间内对方要摸清你的底子还是比较不现实的,所以,有时也是看眼缘,这还是个看脸的时代。
希望大家都能找到合适自己满意的工作!
进阶学习视频
附上:我们之前因为秋招收集的二十套一二线互联网公司Android面试真题 (含BAT、小米、华为、美团、滴滴)和我自己整理Android复习笔记(包含Android基础知识点、Android扩展知识点、Android源码解析、设计模式汇总、Gradle知识点、常见算法题汇总。)
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门,即可获取!
roid源码解析、设计模式汇总、Gradle知识点、常见算法题汇总。)
[外链图片转存中…(img-bqeEtnqY-1714704942440)]
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门,即可获取!