1.导入别人的项目,最好安装一样的版本的Android Studio,否则会多很多错误
且最好是在Android Studio里File->export to zip file导出
导入时import,若有两个选项,选gradle(下面那个),这点记不清了(3.5.2版本)
2.真机调试
(1)Build->Build Bundle(s)/APK(s)->Build APK(s),生成.apk文件拷贝到手机上,安装运行
(2)打开File->Setting->Appearance & Behavior->System Setting->Android SDK,
SDK Tools中选择Google USB Driver安装(一般安装在SDK目录下,eg:E:\Android\sdk\extras\google\usb_driver);在SDK Platforms下载与真机一样的SDK版本(如华为M6平板是Android10)。
设备开启开发者选项,开启USB调试。
USB连接真机,在电脑上打开设备管理器->便携设备,右键移动设备,更新驱动,“浏览计算机以查找驱动”,打开Google USB Driver安装目录,安装。
Run->Run ‘app’,第一次会弹出对话框,选择移动设备即可。
3.手机读写文件
默认路径,或者可以指定SD卡(外部存储)
解决办法:
(1)
(2)
详细参考:https://stackoverflow.com/questions/10787942/android-read-only-file-system-ioexception
若报错
java.lang.RuntimeException: java.lang.IllegalArgumentException: File *** contains a path separator
则:
4.android写多sheet的excel
jxl只可写xls
poi可写xls和xlsx
public static void exportExcel(XSSFWorkbook workbook, int sheetNum, String sheetTitle, List<String> headers,
List<String> result) throws Exception {
XSSFSheet sheet = workbook.createSheet();// 第一步,创建一个workbook,对应一个Excel以xsl为扩展名文件
workbook.setSheetName(sheetNum, sheetTitle);
sheet.setDefaultColumnWidth((short) 30);//设置列宽度大小
//XSSFCellStyle xssfCellStyleHeader = getAndSetXSSFCellStyleHeader(workbook);//第二步, 生成表格第一行的样式和字体
XSSFRow row = sheet.createRow(0);// 产生表格标题行
for (int i = 0; i < headers.size(); i++) {
XSSFCell cell = row.createCell(i);// 序号
//cell.setCellStyle(xssfCellStyleHeader);
XSSFRichTextString text = new XSSFRichTextString(headers.get(i));
cell.setCellValue(text.toString());
}
// 第三步:遍历集合数据,产生数据行,开始插入数据
if (result != null && !result.isEmpty()) {
row = sheet.createRow(1);
for (int i = 0; i < result.size(); i++) {
XSSFCell cell = row.createCell(i);
cell.setCellValue(result.get(i));
}
}
}
5.android获取手机内部存储(更新)
在第一个Activity里的onCreate里加入以下代码
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
Log.i("TEST","Granted");
} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);//1 can be another integer
}
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
Log.i("TEST","Granted");
} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);//1 can be another integer
}
写xlsx文件:
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/applll/"+acc_ID_time+"/";
File DirFile = new File(path);
if (!DirFile.exists()) {
DirFile.mkdirs();
}
int sheetnums=0;
File file = new File(path + acc_ID_time + ".xlsx");//获取excel文件对象
XSSFWorkbook workbook = new XSSFWorkbook();
try {
OutputStream out = new FileOutputStream(file);
Utility.exportExcel(workbook, sheetnums++, "起火部位信息", Utility.CELL_HEADSBBB, Utility.convertDataToRowBBB(infoBBB.get(0)));
workbook.write(out);
out.close();
}catch (Exception e) {
e.printStackTrace();
}
生成的Excel可以在Device File Explorer里的sdcard/DCIM/applll下看到,或直接在真机上内部存储/DCIM/applll看到。
6.一定注意SQL语句写对
特别是查询:
Cursor cursor = db.rawQuery("select * from baseinfo_aTPP where Acc_ID = ?", new String[]{acc_ID_time});
if (cursor != null && cursor.getCount() > 0) {
...
while (cursor.moveToNext()) {
String a= cursor.getString(cursor.getColumnIndex(args1[0]));
...
}
cursor.close();
}
7.当数据库修改时,特别是对数据库表的修改,要在Android Studio里View->Tool Windows->Device File Explorer ,找到路径,删除旧db文件,否则报错
8.修改APP名字
AndroidManifest.xml里的标签下的android:label属性