活动不是从通知开始

时间:2018-11-13 12:50:49

标签: android firebase google-cloud-firestore android-notifications

我正在尝试将通知设置为直接导致特定活动。我遵循了official documentation中概述的步骤。但是单击通知只会打开应用程序的主启动器。

我要通过通知启动的活动是DetailActivity。

这是我在manifest.xml中设置活动层次结构的方式

    <activity
        android:name=".SplashscreenActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".HomeActivity"
        android:parentActivityName=".SplashscreenActivity"/>
    <activity
        android:name=".DetailActivity"
        android:parentActivityName=".HomeActivity"/>

在我的onMessageReceived类的FirebaseMessagingService方法中,我具有以下内容:

        Intent resultIntent = new Intent(this, DetailActivity.class);
        // Create the TaskStackBuilder and add the intent, which inflates the back stack
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        stackBuilder.addNextIntentWithParentStack(resultIntent);
        // Get the PendingIntent containing the entire back stack
        PendingIntent intent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        mNotificationManager.notify(
                NOTIFICATION_ID,
                getNotification("title", "text", intent)
        );

getNotification方法:

private Notification getNotification(String title, String text, PendingIntent intent) {

    return new NotificationCompat.Builder(this, CHANNEL_ID)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(title)
            .setContentText(text)
            .setContentIntent(intent)
            .setOngoing(true)
            .build();
}

我不知道这个问题是否是我要启动的活动不是启动程序活动的直接子级。而且我也不知道如何调试它。希望以前有人遇到过这个奇怪的问题!

2 个答案:

答案 0 :(得分:0)

使用此:

Intent notificationIntent = new Intent(this, DetailActivity.class);

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent. FLAG_ONE_SHOT);

并在Notification中使用该未决意图。

答案 1 :(得分:-1)

install.packages("httr")
install.packages("jsonlite")
install.packages("curl")
library(httr)
library(jsonlite)
library(curl)

h <- new_handle()

handle_setform(h,
    "grant_type"="client_credentials",
    "resource"="https://management.core.windows.net/",
    "client_id"="Application_ID",
    "client_secret"="Client_Secret")

req <- curl_fetch_memory("https://login.windows.net/3977e63c-42bc-4e42-9204-905502b6be1e/oauth2/token", handle = h)
res <- fromJSON(rawToChar(req$content))
r <- httr::GET("https://us2biglobaladlsprd001.azuredatalakestore.net/webhdfs/v1/?op=LISTSTATUS", add_headers(Authorization = paste(res$token_type,res$access_token)))

jsonlite::toJSON(jsonlite::fromJSON(content(r,"text")), pretty = TRUE)

通知代码