【问题标题】:Current app instance hide when Notification is click to open PDF file using intent. How to make that current app instance visible?单击通知以使用意图打开 PDF 文件时,当前应用程序实例隐藏。如何使当前的应用程序实例可见?
【发布时间】:2017-01-10 17:59:26
【问题描述】:

应用流程

  1. app生成PDF后,通知PDF文件使用notification创建。

  2. 点击通知后,将使用 intent(其他 PDF 阅读器应用程序,如 Adob​​e Reader)打开 PDF 文件。

  3. 然后 PDF 文件将打开,并且在按下返回按钮时,app 实例被隐藏(代替显示 app 实例)。

     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());
    

【问题讨论】:

  • 你的问题是?
  • 在打开 PDF 文件后按返回按钮(例如:通过 adobe reader)...当前应用程序实例被添加到应用程序堆栈...如何使当前应用程序实例可见?

标签: android android-intent pdf-generation android-notifications android-pendingintent


【解决方案1】:

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

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

【讨论】:

  • Okey 知道了。谢谢 David Wasser。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-03
  • 1970-01-01
  • 2015-12-24
  • 1970-01-01
  • 2015-01-12
  • 1970-01-01
相关资源
最近更新 更多