【问题标题】:catch activity not found exception in a pendingIntent.getActivity在 pendingIntent.getActivity 中发现未发现活动异常
【发布时间】:2016-06-23 15:33:48
【问题描述】:

我有一个通知操作“评价应用程序”的未决意图,该通知操作将我带到 Playstore 对应用程序进行评价。 使用正常的意图并在应用程序中使用 startActivity(),我们可以处理 activitynotfound 异常,然后将用户带到浏览器中应用程序的 web url。我希望通过单击通知操作进行类似的异常处理。

这里是代码 sn-p

Uri uri = Uri.parse("market://details?id=" + context.getPackageName());
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
PendingIntent ratePendingIntent = PendingIntent.getActivity(context, requestID + 1, goToMarket, PendingIntent.FLAG_UPDATE_CURRENT);
action = new android.support.v4.app.NotificationCompat.Action(android.R.drawable.star_on, "Rate me",ratePendingIntent);

然后我只需将此操作设置为通知生成器, builder.setAction(action);

【问题讨论】:

    标签: android android-notifications android-pendingintent


    【解决方案1】:

    我认为您正在使用没有谷歌播放服务的模拟器。

    确保您刷入 google play 服务。

    【讨论】:

    • 是的,但无论如何,捕获异常都是一个好习惯。
    • try catch 块将是最简单和最安全的实现方式。但你知道这取决于你如何发展。例如,我喜欢带有 if 控制的返回代码。
    • 我知道这是旧的,但我正在寻找相同问题的答案。 try/catch 块将不起作用,因为在 PendingIntent 触发之前不会引发异常。你在 try 块中要做的就是设置 PendingIntent。
    猜你喜欢
    • 2010-12-11
    • 1970-01-01
    • 2016-03-06
    • 1970-01-01
    • 1970-01-01
    • 2019-04-01
    • 2015-11-07
    • 2014-04-22
    • 2013-07-28
    相关资源
    最近更新 更多