Android的即时通讯(db文件无网络),建议肯定要学习(1)

return intent;

}

// Android获取一个用于打开PPT文件的intent

public static Intent getPptFileIntent(Context context,String param) {

Intent intent = new Intent(“android.intent.action.VIEW”);

intent.addCategory(“android.intent.category.DEFAULT”);

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

// Uri uri = Uri.fromFile(new File(param));

Uri uri = FileProvider.getUriForFile(context, “com.datab.cn.fileprovider”, new File(param));

intent.setDataAndType(uri, “application/vnd.ms-powerpoint”);

return intent;

}

// Android获取一个用于打开Excel文件的intent

public static Intent getExcelFileIntent(Context context,String param) {

Intent intent = new Intent(“android.intent.action.VIEW”);

intent.addCategory(“android.intent.category.DEFAULT”);

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

// Uri uri = Uri.fromFile(new File(param));

Uri uri = FileProvider.getUriForFile(context, “com.datab.cn.fileprovider”, new File(param));

intent.setDataAndType(uri, “application/vnd.ms-excel”);

return intent;

}

// Android获取一个用于打开Word文件的intent

public static Intent getWordFileIntent(Context context,String param) {

Intent intent = new Intent(“android.intent.action.VIEW”);

intent.addCategory(“android.intent.category.DEFAULT”);

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

// Uri uri = Uri.fromFile(new File(param));

Uri uri = FileProvider.getUriForFile(context, “com.datab.cn.fileprovider”, new File(param));

intent.setDataAndType(uri, “application/msword”);

return intent;

}

public static Intent getTextFileIntent(Context context,String param, boolean paramBoolean) {

Intent intent = new Intent(“android.intent.action.VIEW”);

intent.addCategory(“android.intent.category.DEFAULT”);

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

if (paramBoolean) {

Uri uri1 = Uri.parse(param);

intent.setDataAndType(uri1, “text/plain”);

} else {

// Uri uri2 = Uri.fromFile(new File(param));

Uri uri2 = FileProvider.getUriForFile(context, “com.datab.cn.fileprovider”, new File(param));

intent.setDataAndType(uri2, “text/plain”);

}

return intent;

}

// Android获取一个用于打开APK文件的intent

public static Intent getAllIntent(Context context,String param) {

Intent intent = new Intent();

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

intent.setAction(android.content.Intent.ACTION_VIEW);

Uri uri = Uri.fromFile(new File(param));

intent.setDataAndType(uri, “/”);

return intent;

}

3.发送图片和intent打开.jpg文件如下:


在这里插入图片描述

1.ChatActivity.java中:

private void pickImage() {

Intent pickIntent = new Intent(Intent.ACTION_GET_CONTENT);

pickIntent.setType(“image/*”);

startActivityForResult(pickIntent, REQUEST_IMAGE_PICKER);

}

如下图:

在这里插入图片描述

2.发送图片后把图片放在手机文件管理里

1.(/storage/emulated/0/Android/data/包名/files/Pictures/sent),FileUtils.java中:

context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);

2.ChatActivity.java中:

private File createSentImageFile(Context context, String fileName, Bitmap bitmap) throws IOException {

file = new File(FileUtils.getSentImagesDir(context), fileName + FileUtils.IMAGE_EXTENSION);

FileOutputStream outputStream = new FileOutputStream(file);

bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);

outputStream.flush();

outputStream.close();

return file;

}

3.FileUtils.java中:

public static File getSentImagesDir(Context context) {

File dir = new File(getImagesDir(context), “sent”);

if (!dir.exists()) {

dir.mkdirs();

}

return dir;

}

private static File getImagesDir(Context context) {

return isExternalStorageWritable() ? context.getExternalFilesDir(Environment.DIRECTORY_PICTURES) : context.getDir(“images”, Context.MODE_PRIVATE);

}

如下图:

在这里插入图片描述

4.发送文件如下:


1.txt文件

在这里插入图片描述

2.apk文件

在这里插入图片描述

1.ChatActivity.java中:

private void pickFile() {

Intent pickIntent = new Intent(Intent.ACTION_GET_CONTENT);

pickIntent.setType(“/”);

pickIntent.addCategory(Intent.CATEGORY_OPENABLE);

startActivityForResult(pickIntent, REQUEST_FILE_PICKER);

}

如下图:

在这里插入图片描述

2.发送图片后把图片放在手机文件管理里:ChatActivity中:

private File createSentFile(Context context, String filename, String fileend, byte[] bytes) {

String end = null;

if(fileend.equals(FileUtils.IMAGE_EXTENSION)) {

end = fileend;

}else if (fileend.equals(FileUtils.FILE_GIF_EXTENSION)) {

end = fileend;

}else if (fileend.equals(FileUtils.FILE_PNG_EXTENSION)) {

end = fileend;

}else if (fileend.equals(FileUtils.FILE_JPEG_EXTENSION)){

end = fileend;

}else if (fileend.equals(FileUtils.FILE_APK_EXTENSION)){

end = fileend;

}else if (fileend.equals(FileUtils.FILE_PPT_EXTENSION)){

end = fileend;

}else if (fileend.equals(FileUtils.FILE_XLS_EXTENSION)){

end = fileend;

}else if (fileend.equals(FileUtils.FILE_DOC_EXTENSION)){

end = fileend;

}else if (fileend.equals(FileUtils.FILE_TXT_EXTENSION)){

end = fileend;

}

file = new File(FileUtils.getSentFileDir(context), filename + end);

try {

FileOutputStream outStream = new FileOutputStream(file);

outStream.write(bytes);

outStream.close();

} catch (IOException e) {

e.printStackTrace();

}

return file;

}

如下图:

在这里插入图片描述

2.对话记录放在db文件里

============================================================================

1.用虚拟机查看db文件信息


1.ChatDbHelper.java中:

public static final int DATABASE_VERSION = 1;

public static final String DATABASE_NAME = “chat.db”;

public static final String TEXT_TYPE = " TEXT";

public static final String INTEGER_TYPE = " INTEGER";

public static final String COMMA_SEP = “,”;

private static ChatDbHelper instance;

public static synchronized ChatDbHelper getInstance(Context context) {

if (instance == null) {

instance = new ChatDbHelper(context.getApplicationContext());

}

return instance;

}

public ChatDbHelper(Context context) {

super(context, DATABASE_NAME, null, DATABASE_VERSION);

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新

如果你觉得这些内容对你有帮助,可以添加V获取:vip204888 (备注Android)
img

写在最后

对程序员来说,很多技术的学习都是“防御性”的。也就是说,我们是在为未来学习。我们学习新技术的目的,或是为了在新项目中应用,或仅仅是为了将来的面试。但不管怎样,一定不能“止步不前”,不能荒废掉。

![
[]


文章以下内容会给出阿里与美团的面试题(答案+解析)、面试题库、Java核心知识点梳理等

写在最后

对程序员来说,很多技术的学习都是“防御性”的。也就是说,我们是在为未来学习。我们学习新技术的目的,或是为了在新项目中应用,或仅仅是为了将来的面试。但不管怎样,一定不能“止步不前”,不能荒废掉。

[外链图片转存中…(img-xhAIAyX1-1711922624020)]

[外链图片转存中…(img-R1Bho5tM-1711922624020)]
[]

[外链图片转存中…(img-WkhVfAFe-1711922624021)]
[外链图片转存中…(img-BW01NPay-1711922624021)]

文章以下内容会给出阿里与美团的面试题(答案+解析)、面试题库、Java核心知识点梳理等

本文已被CODING开源项目:《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》收录

  • 28
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值