如何从通知中打开PDF文件

时间:2019-08-12 16:18:24

标签: android pdf android-notifications android-pendingintent

点击我尝试过的通知后,我必须打开pdf文件:

createNotificationChannel();
    File file = new File(path);

    Uri selectedUri = Uri.parse(file.getAbsolutePath());
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    //intent.setDataAndType(selectedUri, "resource/folder");
    intent.setDataAndType(selectedUri, "pdf/*");

    //PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    final PendingIntent contentIntent = PendingIntent.getActivity(this, 0,intent, 0);


    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "0");
    builder.setSmallIcon(R.drawable.ic_notification);
    builder.setContentTitle(nomePdf + " creato");
    builder.setContentText("Il tuo pdf è stato salvato nella cartella download");
    builder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
    builder.setAutoCancel(true);
    builder.setContentIntent(contentIntent);


    NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
    notificationManagerCompat.notify(0, builder.build());

它可以工作,但是会打开文件管理器,而不是

0 个答案:

没有答案