Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue in setting the downloader #29

Open
piyushshende76 opened this issue Jul 5, 2020 · 9 comments
Open

issue in setting the downloader #29

piyushshende76 opened this issue Jul 5, 2020 · 9 comments

Comments

@piyushshende76
Copy link

sir, I used your downloader it's very useful but I am not able to detect if the file in mp3 video or apk and if the app stops it again shows the downloaded file in downloading the list, as I split the data in two recycler view like ongoing download and completed download it does not refresh at the time

I major problem is with the task should verify what task is it like mp3 video or apk file

please help me with this out.

@piyushshende76
Copy link
Author

I want to make it like UC browser, download manager
Screenshot_20200705-231727_Pump 1

@piyushshende76
Copy link
Author

I tried it with replacing the getdownloadingall with getdownloading and getdownloaded it works but still, if I download an mp3 file it crashes the app and again if I open I show the file in downloading queue

@huxq17
Copy link
Owner

huxq17 commented Jul 6, 2020

You can verify download file by add a downloadInterceptor.
image

@huxq17
Copy link
Owner

huxq17 commented Jul 6, 2020

I tried it with replacing the getdownloadingall with getdownloading and getdownloaded it works but still, if I download an mp3 file it crashes the app and again if I open I show the file in downloading queue

Can you show the crash stack trace?

@piyushshende76
Copy link
Author

no, I was not able to trace the crash stack and sir I used the downloadInterceptor but unable to understand the flow of the code and how to verify it, sir if it possible can you update some the downloadInterceptor to automatically verify the file type, please

@piyushshende76
Copy link
Author

to verify I have tried this type of code

case FINISHED:

                   playMusic(downloadInfo.getFilePath());
                    Log.i("TAG", "filepath: "+ downloadInfo.getFilePath());


                    break;
            }
        }

    }

    private void playMusic(String filePath) {
        Context context = itemView.getContext();
        File mp3File = new File(filePath);
        Intent intent = new Intent();
       intent.setAction(Intent.ACTION_VIEW);
        Uri uri;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        uri = FileProvider.getUriForFile(context, context.getPackageName() + ".fileProvider-installApk", mp3File);
        // intent = new Intent(Intent.ACTION_VIEW);
        if (mp3File.toString().contains(".doc") || mp3File.toString().contains(".docx")) {
            // Word document
            intent.setDataAndType(uri, "application/msword");
        } else if (mp3File.toString().contains(".pdf")) {
            // PDF file
            intent.setDataAndType(uri, "application/pdf");
        } else if (mp3File.toString().contains(".ppt") || mp3File.toString().contains(".pptx")) {
            // Powerpoint file
            intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
        } else if (mp3File.toString().contains(".xls") || mp3File.toString().contains(".xlsx")) {
            // Excel file
            intent.setDataAndType(uri, "application/vnd.ms-excel");
        } else if (mp3File.toString().contains(".zip") || mp3File.toString().contains(".rar")) {
            // WAV audio file
            intent.setDataAndType(uri, "application/x-wav");
        } else if (mp3File.toString().contains(".rtf")) {
            // RTF file
            intent.setDataAndType(uri, "application/rtf");
        } else if (mp3File.toString().contains(".wav") || mp3File.toString().contains(".mp3")) {
            // WAV audio file
            intent.setDataAndType(uri, "audio/*");
        } else if (mp3File.toString().contains(".gif")) {
            // GIF file
            intent.setDataAndType(uri, "image/gif");
        } else if (mp3File.toString().contains(".jpg") || mp3File.toString().contains(".jpeg") || mp3File.toString().contains(".png")) {
            // JPG file
            intent.setDataAndType(uri, "image/jpeg");
        } else if (mp3File.toString().contains(".txt")) {
            // Text file
            intent.setDataAndType(uri, "text/plain");
        } else if (mp3File.toString().contains(".3gp") || mp3File.toString().contains(".mpg") || mp3File.toString().contains(".mpeg") || mp3File.toString().contains(".mpe") || mp3File.toString().contains(".mp4") || mp3File.toString().contains(".avi")) {
            // Video files
            intent.setDataAndType(uri, "video/*");
        } else {
            //if you want you can also define the intent type for any other file
            //additionally use else clause below, to manage other unknown extensions
            //in this case, Android will show all applications installed on the device
            //so you can choose which application to use
            intent.setDataAndType(uri, "*/*");
        }
        } else {
            uri = Uri.fromFile(mp3File);
        }
      //  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        try {
            context.startActivity(intent);
        } catch (ActivityNotFoundException ignore) {
            Toast.makeText(context, "Do you have an  player?", Toast.LENGTH_LONG).show();
        }



    }

@huxq17
Copy link
Owner

huxq17 commented Jul 6, 2020

to verify I have tried this type of code

case FINISHED:

                   playMusic(downloadInfo.getFilePath());
                    Log.i("TAG", "filepath: "+ downloadInfo.getFilePath());


                    break;
            }
        }

    }

    private void playMusic(String filePath) {
        Context context = itemView.getContext();
        File mp3File = new File(filePath);
        Intent intent = new Intent();
       intent.setAction(Intent.ACTION_VIEW);
        Uri uri;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        uri = FileProvider.getUriForFile(context, context.getPackageName() + ".fileProvider-installApk", mp3File);
        // intent = new Intent(Intent.ACTION_VIEW);
        if (mp3File.toString().contains(".doc") || mp3File.toString().contains(".docx")) {
            // Word document
            intent.setDataAndType(uri, "application/msword");
        } else if (mp3File.toString().contains(".pdf")) {
            // PDF file
            intent.setDataAndType(uri, "application/pdf");
        } else if (mp3File.toString().contains(".ppt") || mp3File.toString().contains(".pptx")) {
            // Powerpoint file
            intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
        } else if (mp3File.toString().contains(".xls") || mp3File.toString().contains(".xlsx")) {
            // Excel file
            intent.setDataAndType(uri, "application/vnd.ms-excel");
        } else if (mp3File.toString().contains(".zip") || mp3File.toString().contains(".rar")) {
            // WAV audio file
            intent.setDataAndType(uri, "application/x-wav");
        } else if (mp3File.toString().contains(".rtf")) {
            // RTF file
            intent.setDataAndType(uri, "application/rtf");
        } else if (mp3File.toString().contains(".wav") || mp3File.toString().contains(".mp3")) {
            // WAV audio file
            intent.setDataAndType(uri, "audio/*");
        } else if (mp3File.toString().contains(".gif")) {
            // GIF file
            intent.setDataAndType(uri, "image/gif");
        } else if (mp3File.toString().contains(".jpg") || mp3File.toString().contains(".jpeg") || mp3File.toString().contains(".png")) {
            // JPG file
            intent.setDataAndType(uri, "image/jpeg");
        } else if (mp3File.toString().contains(".txt")) {
            // Text file
            intent.setDataAndType(uri, "text/plain");
        } else if (mp3File.toString().contains(".3gp") || mp3File.toString().contains(".mpg") || mp3File.toString().contains(".mpeg") || mp3File.toString().contains(".mpe") || mp3File.toString().contains(".mp4") || mp3File.toString().contains(".avi")) {
            // Video files
            intent.setDataAndType(uri, "video/*");
        } else {
            //if you want you can also define the intent type for any other file
            //additionally use else clause below, to manage other unknown extensions
            //in this case, Android will show all applications installed on the device
            //so you can choose which application to use
            intent.setDataAndType(uri, "*/*");
        }
        } else {
            uri = Uri.fromFile(mp3File);
        }
      //  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        try {
            context.startActivity(intent);
        } catch (ActivityNotFoundException ignore) {
            Toast.makeText(context, "Do you have an  player?", Toast.LENGTH_LONG).show();
        }



    }

downloadInterceptor allows you to verify the integrity of the file,if get the type of file, this way is required.

@piyushshende76
Copy link
Author

sir sorry but I am not able to read or verify file from downloadInterceptor
please help me with this issue

@huxq17
Copy link
Owner

huxq17 commented Jul 6, 2020

downloadInterceptor is not support this issue yet, your code is a nice way so far. I will support get file's type from downloadinfo at future's version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants