小编And*_*ser的帖子

android从zip文件解压缩文件夹并从该文件夹中读取内容

在我的一个应用程序中,我需要提取一个包含文件夹的zip文件,该文件夹包含图像,这意味着abc.zip => adb(文件夹)=> abc.png我要提取图像文件

我用下面的方法

 private boolean extractFolder(File destination, File zipFile) throws ZipException, IOException
    {
        int BUFFER = 8192;
        File file = zipFile;
        //This can throw ZipException if file is not valid zip archive
        ZipFile zip = new ZipFile(file);
//        String newPath = destination.getAbsolutePath() + File.separator + FilenameUtils.removeExtension(zipFile.getName());
        String newPath = destination.getAbsolutePath() + File.separator + zipFile.getName();
        //Create destination directory
        new File(newPath).mkdir();
        Enumeration zipFileEntries = zip.entries();

        //Iterate overall zip file entries
        while (zipFileEntries.hasMoreElements())
        {
            ZipEntry entry = (ZipEntry) zipFileEntries.nextElement();
            String currentEntry …
Run Code Online (Sandbox Code Playgroud)

directory android image unzip

4
推荐指数
1
解决办法
941
查看次数

Android:将 FCM 通知保存到 Room DB

我正在使用 firebase FCM 来获取通知。我想要如果收到通知,它应该存储在我的 RoomDatabase 中。稍后,当用户打开应用程序时,将在通知部分显示所有通知

我正在使用 MVVM,我试图通过ViewModel进行保存,但它不起作用。这是我目前的代码。

public class MessagingService extends FirebaseMessagingService {

    @Override
    public void onNewToken(String s) {
        super.onNewToken(s);
        Log.d("MessagingService", s);
    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        // Check if message contains a notification payload.

        if (remoteMessage.getData().isEmpty()){
            showNotification(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());
        } else {
            showNotification(remoteMessage.getData());
        }

    }

    private void showNotification(Map<String, String> data) {


        Bitmap bitmap;

        String title = data.get("title").toString();
        String body = data.get("body").toString();
        String imageUri = data.get("image").toString();
        String TrueOrFalse = data.get("AnotherActivity").toString();

        bitmap = getBitmapfromUrl(imageUri); …
Run Code Online (Sandbox Code Playgroud)

android android-sqlite firebase-cloud-messaging android-mvvm android-room

4
推荐指数
1
解决办法
2936
查看次数