2016-10-03 13 views
0

、私は、Webクライアントを使用してAndroidのAppでファイルをダウンロードしてください。ローカルフォルダに保存されます。 私は通知からダウンロードしたファイルを開きたいコード?私Xamarinフォームで

  webClient.DownloadFile(filePath, localPath); 
      Notification.Builder builder = new Notification.Builder(Android.App.Application.Context) 
.SetContentTitle("Download Successfully") 
.SetContentText("Click here to open") 
.SetSmallIcon(Resource.Drawable.abc_btn_colored_material); 
      Notification notification = builder.Build(); 
      NotificationManager notificationManager = 
Android.App.Application.Context.GetSystemService(Context.NotificationService) as NotificationManager; 
      const int notificationId = 0; 
      notificationManager.Notify(notificationId, notification); 

以下のように、これはAndroidの通知を使用して言及されます。どのように私はそれを行うことができます。私はXamarinが初めてです。解決策を提案してください。

答えて

0

通知のためににIntentという名前を付けて作成することができます。これにはファイルのアクションビューが含まれています。 、

notification.SetContentIntent(pendingIntent); 

さて、あなたはIntentを与えるfilePathには、Android上のすべてのアプリケーションからアクセスできるどこかでなければなりません。そして、あなたはあなたのNotificationビルダーでIntentという設定

var mimeTypeMap = MimeTypeMap.Singleton; 
var mimeType = mimeTypeMap.GetMimeTypeFromExtension(System.IO.Path.GetExtension(filePath)); 

var intent = new Intent(); 
intent.SetAction(Intent.ActionView); 
intent.SetDataAndType(Android.Net.Uri.Parse(filePath), mimeType); 

var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot); 

:これは次のようになりますさもなければそれを開くことは失敗する。したがって、ファイルを保存するときは、公共の場所で外部ストレージに保存してください。

+0

新しいAndroid.Net.Uri(filePathに)ショーがインタフェースウリ –

+1

申し訳ありませんの抽象クラスのインスタンスを作成することはできません、それは '' Uri.Parse(filePathに)する必要があります。 – Cheesebaron

関連する問題