8.2
8.3
-
回顾
-
Activity与AppCompatActivity的区别,继承AppCompatActivity时在界面最上面会出现一个ActionBar,默认显示项目的名称。去掉ActionBar:getSupportActionBar().hide(); -
图片存储 1.存在全局内存中:MainApplication.getInstance().mIconMap.put(rowid,thumb); Bitmap thumb = BitmapFactory.decodeResource(getResources(),mThumbArray[i]);
MainApplication.getInstance().mIconMap.put(rowid,thumb);
iv_thumb.setImageBitmap(MainApplication.getInstance().mIconMap.get(info.rowid));
-
2.存在SD卡中: FileUtil.saveImage(pic_path, pic); bitmap.compress(Bitmap.CompressFormat.JPEG, 80, bos)
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/";
Bitmap pic = BitmapFactory.decodeResource(getResources(), mPicArray[i]);
String pic_path = path + rowid + ".jpg";
FileUtil.saveImage(pic_path, pic);
pic.recycle();
info.pic_path = pic_path;
mGoodsHelper.update(info);
public static void saveImage(String path, Bitmap bitmap) {
try {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(path));
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, bos);
bos.flush();
bos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Bitmap pic = BitmapFactory.decodeFile(info.pic_path);
- 使用内部类解决多重继承的问题。
- 进度条<ProgressBar
- get请求与post请求。get请求用于从指定资源请求数据,查询字符串在URL中发送。post请求用于将数据发送到服务器来创建更新资源。
8.4
8.5
-
HTTP与FTP:HTTP超文本传输协议,面向网页。FTP文件传输协议,面向文件。 -
匿名内部类是表达式,定义完后用“;”结束。 -
文件上传:上传功能需要自己写代码实现 protected String doInBackground(String... params) {
String uploadUrl = params[0];
String filePath = params[1];
String result = HttpUploadUtil.upload(uploadUrl, filePath);
return result;
}
public static String upload(String uploadUrl, String uploadFile) {
String fileName = "";
int pos = uploadFile.lastIndexOf("/");
if (pos >= 0) {
fileName = uploadFile.substring(pos + 1);
}
String end = "\r\n";
String Hyphens = "--";
String boundary = "WUm4580jbtwfJhNp7zi1djFEO3wNNm";
try {
URL url = new URL(uploadUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Charset", "UTF-8");
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
DataOutputStream ds = new DataOutputStream(conn.getOutputStream());
ds.writeBytes(Hyphens + boundary + end);
ds.writeBytes("Content-Disposition: form-data; "
+ "name=\"file1\";filename=\"" + fileName + "\"" + end);
ds.writeBytes(end);
FileInputStream fStream = new FileInputStream(uploadFile);
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
int length = -1;
while((length = fStream.read(buffer)) != -1) {
ds.write(buffer, 0, length);
}
ds.writeBytes(end);
ds.writeBytes(Hyphens + boundary + Hyphens + end);
fStream.close();
ds.flush();
InputStream is = conn.getInputStream();
int ch;
StringBuffer b = new StringBuffer();
while ((ch = is.read()) != -1) {
b.append((char) ch);
}
ds.close();
return "SUCC";
} catch (Exception e) {
e.printStackTrace();
return "上传失败:" + e.getMessage();
}
}
8.6
-
InetAddress 检查设备与某个网络的连通性 -
Socket的原意是“插座”,应用层就可以和传输层通过套接字接口,区分来自不同应用程序进程或网络连接的通信,实现数据传输的并发服务 -
ListView列表视图和GridView网格视图与adapter结合,显示数据。 -
ExpandableListView可折叠列表视图
8.9
8.10
- Activity的生命周期:onCreate,onStart,onResume,onPause,onStop,onDestroy,onRestart
- Service的生命周期:onCreate,onStartCommand,onDestroy,onBind,onRebind,onUnbind
图片来自网络
-
SeekBar拖动条,ScrollView 滚动视图 -
AudioRecorder 音频录制,AudioPlayer 音频播放 -
requestWindowFeature(Window.FEATURE_NO_TITLE); 启用窗体的扩展特性 -
MedioPlayer 媒体播放器 -
get通过url来传输,不够安全,而post通过请求实体传输,安全性较高;get对传输的数据量大小有限制,而post没有。 -
URI与URL,唯一标识资源的都被称为URI。URL是一种具体的URI,它是URI的一个子集,它不仅唯一标识资源,而且还提供了定位该资源的信息。 -
Broadcast 广播,适配器向页面传回数据,registerReceiver注册广播,unregisterReceiver注销广播 -
实现获取APK文件中的包信息和版本,判断是否为最新版本,调用API接口下载。
8.11
8.12
-
1.获取手机上App的版本信息 2.获取接口中的apk版本信息 3.通过接口下载 -
Android6.0以上版本,动态获取权限。 动态权限设置
private void setPermissions() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int REQUEST_CODE_CONTACT = 101;
String [] permissions = {
android.Manifest.permission.READ_EXTERNAL_STORAGE,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE};
for (String str : permissions) {
if (this.checkSelfPermission(str) != PackageManager.PERMISSION_GRANTED){
this.requestPermissions(permissions,REQUEST_CODE_CONTACT);
return;
}
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 101) {
Log.d(TAG,"权限开启成功");
}else {
Log.d(TAG,"权限开启失败");
}
}
-
for (String str : permissions) {…}
8.13
- String、StringBuffer、StringBuilder
|