0
我有一個通知信使,我希望用戶在按下「推送通知」時有權訪問Google Play商店,否則將其重定向到網址。 所以我的代碼是這樣的:如何在通知中打開新的意圖時處理異常?
Intent intent = new Intent(new Intent(Intent.ACTION_VIEW, Uri.parse("market://dev?id=" + appPackageName2)));
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.setContentTitle("FCM Notification")
.setContentText(remoteMessage.getNotification().getBody())
.setAutoCancel(true)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
我想在上面的代碼是這樣的:
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://dev?id=" + appPackageName2)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/dev?id=" + appPackageName2)));
}