public bool OnMenuItemClick(IMenuItem item)
        {
            if (string.IsNullOrEmpty(_itemExtra))
            {
                return(false);
            }

            var fileName = _itemExtra.StartsWith("data:image") ?
                           $"image.{DataImage.GetImageExtension(_itemExtra)}" :
                           URLUtil.GuessFileName(_itemExtra, null, null);

            if (FileHelper.MediaExists(fileName))
            {
                UserDialogs.Instance.ActionSheet(new ActionSheetConfig()
                                                 .SetTitle("An image with the same name already exists")
                                                 .SetMessage($"Do you want replace the existing {fileName} in download")
                                                 .Add(
                                                     "Replace file",
                                                     () => new ImageDownloader().Execute(_itemExtra, fileName))
                                                 .Add(
                                                     "Create new file",
                                                     () => new ImageDownloader().Execute(_itemExtra, FileHelper.GenerateNewFileName(fileName)))
                                                 .SetCancel()
                                                 .SetUseBottomSheet(true));
            }
            else
            {
                new ImageDownloader().Execute(_itemExtra, fileName);
            }

            return(true);
        }
示例#2
0
        public async Task DownloadAndInstall(DownloadManager manager)
        {
            string url     = @"https://app.cforce.live/com.payforce.apk";
            var    source  = Android.Net.Uri.Parse(url);
            var    request = new DownloadManager.Request(source);

            request.AllowScanningByMediaScanner();
            request.SetAllowedOverRoaming(true);
            request.SetDescription("Downloading PayForce");
            request.SetAllowedOverMetered(true);
            request.SetVisibleInDownloadsUi(true);
            string filename = URLUtil.GuessFileName(url, null, MimeTypeMap.GetFileExtensionFromUrl(url));

            MainActivity.FileName = filename;
            request.SetDestinationInExternalPublicDir(Android.OS.Environment.DirectoryDownloads, filename);
            request.SetNotificationVisibility(DownloadManager.Request.VisibilityVisibleNotifyCompleted);
            request.SetAllowedNetworkTypes(DownloadNetwork.Wifi | DownloadNetwork.Mobile);
            MainActivity.DownloadId = manager.Enqueue(request);
        }
        private void InstallVideo()
        {
            try
            {
                if (File.Exists(Path.Combine(storagePath, GetString(Resource.String.app_name), URLUtil.GuessFileName(videoPath, null, MimeTypeMap.GetFileExtensionFromUrl(videoPath)))))
                {
                    Toast.MakeText(this, GetString(Resource.String.video_already_downloaded), ToastLength.Short).Show();
                    return;
                }

                var request = new DownloadManager.Request(Uri.Parse(videoPath))
                              .SetTitle(statusTitle)
                              .SetDescription(GetString(Resource.String.load))
                              .SetNotificationVisibility(DownloadVisibility.VisibleNotifyCompleted)
                              .SetDestinationInExternalPublicDir(Environment.DirectoryDownloads, Path.Combine(GetString(Resource.String.app_name), URLUtil.GuessFileName(videoPath, null, MimeTypeMap.GetFileExtensionFromUrl(videoPath))));

                ((DownloadManager)GetSystemService(DownloadService)).Enqueue(request);

                Toast.MakeText(this, GetString(Resource.String.video_downloaded_successfully), ToastLength.Short).Show();
            }
            catch
            {
                Toast.MakeText(this, GetString(Resource.String.error), ToastLength.Short).Show();
            }
        }
        public void ShareVideo(string packageName = "defualt")
        {
            try
            {
                if (!packageName.Equals("defualt") && !IsAppInstalled(packageName))
                {
                    string appName;
                    if (packageName.Equals("com.whatsapp"))
                    {
                        appName = "تطبيق واتس اب ";
                    }
                    else if (packageName.Equals("com.instagram.android"))
                    {
                        appName = "تطبيق انستغرام ";
                    }
                    else
                    {
                        appName = "تطبيق الفيسبوك ";
                    }
                    Toast.MakeText(this, appName + "غير مثبت على جهازك", ToastLength.Short).Show();
                    return;
                }

                if ((int)Build.VERSION.SdkInt >= 23)
                {
                    if (CheckSelfPermission(Manifest.Permission.WriteExternalStorage) != (int)Permission.Granted)
                    {
                        RequestPermissions(new string[] { Manifest.Permission.WriteExternalStorage }, 135489213);
                        return;
                    }
                }

                InstallVideo();

                string path = Path.Combine(storagePath, GetString(Resource.String.app_name), URLUtil.GuessFileName(videoPath, null, MimeTypeMap.GetFileExtensionFromUrl(videoPath)));

                Intent intent = new Intent(Intent.ActionSend);
                intent.SetType("video/*");
                intent.PutExtra(Intent.ExtraText, "هذا الفيديو متوفر على تطبيق حالات فيديو بامكانكم تحميل التطبيق من Google Play مجاناً رابط التحميل\n" + "https://play.google.com/store/apps/details?id=" + PackageName);
                intent.PutExtra(Intent.ExtraStream, Uri.Parse(path));

                if (packageName.Equals("com.whatsapp"))
                {
                    intent.SetPackage(packageName);
                }

                StartActivity(Intent.CreateChooser(intent, GetString(Resource.String.share_with_friends)));
            }
            catch
            {
                Toast.MakeText(this, GetString(Resource.String.error), ToastLength.Short).Show();
            }
        }