使用PendingIntent和NotificationManagerCompat打开Play Store

3

有人知道如何使用NotificationPendingIntent打开Play Store吗?

我想要用我的应用页面打开Play Store,目前已尝试了以下方法。

    Intent i = new Intent(Intent.ACTION_VIEW,
            Uri.parse("market://details?id=" + a.getPackageName()));
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(a, 0, i, 0);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(a, "update")
            .setContentTitle(getStr(a, R.string.notify_update_title))
            .setContentText(getStr(a, R.string.notify_update_body))
            .setSmallIcon(R.drawable.ic_notif)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT)
            .setContentIntent(pendingIntent);

    NotificationManagerCompat managerCompat = NotificationManagerCompat.from(a);
    managerCompat.notify(UPDATE_NOTIF_ID, builder.build());

发生了什么,或者没有发生? - TheWanderer
通知栏是否会像尝试执行某个操作一样关闭? - TheWanderer
尝试将您的PendingIntent请求代码更改为非0的其他值。 - TheWanderer
将其更改为1,它不起作用。 - jbmcle
尝试使用完整的Google Play URL格式,如下所示:"https://play.google.com/store/apps/details?id=" + packageName - TheWanderer
显示剩余4条评论
1个回答

0

我的错。实际上,我正在调试一个非常低端的智能手机API 16,因为我需要Google Play服务最新版本才能使用Firebase,所以我卸载了Google Play。

令人惊讶的是,当我点击通知时,它没有抛出ActivityNotFoundException,表明找不到Google Play。

因此,在API 16中进行了一些小小的警告。

感谢所有帮助过我的人,非常感激。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接