Skip to content

Commit

Permalink
fix file message content
Browse files Browse the repository at this point in the history
  • Loading branch information
imndx committed Apr 21, 2019
1 parent 0b92d14 commit 643399f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import android.view.View;
import android.widget.Toast;

import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;

import java.io.File;

import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.Bind;
import butterknife.OnClick;
import cn.wildfire.chat.kit.annotation.EnableContextMenu;
Expand Down Expand Up @@ -65,7 +66,7 @@ public void onClick(View view) {
}

if (file.exists()) {
Intent intent = FileUtils.getViewIntent(context, new File(fileMessageContent.localPath));
Intent intent = FileUtils.getViewIntent(context, file);
ComponentName cn = intent.resolveActivity(context.getPackageManager());
if (cn == null) {
Toast.makeText(context, "找不到能打开此文件的应用", Toast.LENGTH_SHORT).show();
Expand Down
9 changes: 6 additions & 3 deletions chat/src/main/java/cn/wildfire/chat/kit/utils/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
import android.util.Log;
import android.webkit.MimeTypeMap;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.FileProvider;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileFilter;
Expand All @@ -26,9 +30,6 @@
import java.text.DecimalFormat;
import java.util.Comparator;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.FileProvider;
import okhttp3.ResponseBody;

public class FileUtils {
Expand Down Expand Up @@ -502,6 +503,8 @@ public static Intent getViewIntent(Context context, File file) {
url.contains(".mpe") || url.contains(".mp4") || url.contains(".avi")) {
// Video files
intent.setDataAndType(uri, "video/*");
} else if (url.contains(".apk")) {
intent.setDataAndType(uri, "application/vnd.android.package-archive");
} else {
intent.setDataAndType(uri, "*/*");
}
Expand Down

0 comments on commit 643399f

Please sign in to comment.