当前应用实例在单击通知以使用 Intent 打开 PDF 文件时隐藏.如何使当前应用实例可见



App Flow

  1. 通过应用程序生成 PDF 后,它会通知使用通知创建的 PDF 文件。

  2. 单击通知时,将使用意图打开PDF文件(其他PDF阅读器应用程序,如Adobe Reader)。

  3. 然后 PDF 文件将被打开,按下返回按钮时,应用程序实例将被隐藏(代替显示应用程序实例)。

     mBuilder = new NotificationCompat.Builder(mContext)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle("Resume Builder")
            .setContentText("Creating " + fileName + " .pdf in progress...")
            .setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
            .setAutoCancel(true);
    File pdfFile = new File(Environment.getExternalStorageDirectory() + "/" +
            AppConstants.RESUME_BUILDER_FOLDER + "/" + fileName + ".pdf");
    Uri path = Uri.fromFile(pdfFile);
    Intent resultIntent = new Intent(Intent.ACTION_VIEW);
    resultIntent.setDataAndType(path, "application/pdf");
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder
            .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    mNotificationManager = (NotificationManager) mContext
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(0, mBuilder.build());
    

目前,您的Notification在新任务中打开 PDF 查看器。Android 应该如何知道在查看 PDF 后返回您的应用?

你应该让通知在你自己的应用中打开一个Activity。然后,该Activity可以启动 PDF 查看器。当用户从 PDF 查看器返回时,您的应用程序将位于下方。

最新更新