簡體   English   中英

如何在Android中單擊通知打開相同的活動?

[英]How to open same activity on click of notification in android?

我想打開一個活動, SplashActivity在通知點擊時說SplashActivity ,而不管click_action如何。

目前,通過通知,我收到click_action以處理UI,例如

如果用戶在個人資料頁面上,並且后端團隊從管理控制台更新了他的個人資料。
在這種情況下,應用會收到帶有click_action profile_update的通知。應用會檢查click_action並刷新配置文件頁面。

到目前為止,一切都很好,但是當應用程序在后台運行並且收到帶有click_action profile_update的通知以及用戶單擊通知時-通知將從通知托盤中消失,並且不執行任何導航。

我已經聲明要在單擊通知時打開的SplashScreen ,如下所示:

  <activity
            android:name=".SplashScreen"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
        </activity>

仍然用戶沒有導航到SplashScreen

創建活動的通知傳遞意圖時

NotificationManager notificationManager = (NotificationManager) 
getSystemService(NOTIFICATION_SERVICE);    
Intent intent = new Intent(this, SplashActivity .class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 
PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle("Prayer time")
                    .setContentText("Its " + salatName + " time.")
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentIntent(pIntent)**Pending intent has the intent of activity you want to open **
                    .addAction(R.drawable.close,"Dismiss",snoozePendingIntent)
                    .setAutoCancel(true)
                    .setWhen(System.currentTimeMillis())
                    .setPriority(NotificationCompat.PRIORITY_DEFAULT);
notificationManager.notify(0, builder.build());

在單擊通知時要在待打開的意圖中傳遞活動的意圖

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM