Приложение Flutter не выходит на передний план при нажатии на нативную фоновую службу уведомлений Android - PullRequest
0 голосов
/ 25 октября 2019

Я новичок в изучении флаттера. В моем приложении-флаттере есть собственная фоновая служба Android на kotlin, где у меня работает сокет, и всякий раз, когда сокет слушает что-то, я генерирую уведомление с помощью NotificationCompat.Builder.

Но я не могу вернуть приложение Flutter на передний план, когда пользователь нажимает на уведомление.

Я попытался создать отложенный намерение и передать его в уведомитель Builder setContentIntent (), но ничего не происходит при нажатии.

функция показа уведомлений в собственной фоновой службе:

fun shownotification (){
   packageNamer = this.getPackageName()
   launchIntent = this.getPackageManager().getLaunchIntentForPackage(packageName)
   var className = launchIntent?.getComponent()!!.className.javaClass
   intent.action = "SELECT_NOTIFICATION"

   intent.setClass(this,className)
   pendingIntent = PendingIntent.getActivity(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT)

    var builder = NotificationCompat.Builder(this, "notifications")
            .setOngoing(true)
            .setContentIntent(pendingIntent)
            .setFullScreenIntent(pendingIntent, true)
            .setSmallIcon(R.drawable.common_google_signin_btn_icon_dark)
            .setContentTitle("My notification")
            .setContentText("Much longer text that cannot fit one line...")
            .setStyle(NotificationCompat.BigTextStyle()
            .bigText("Much longer text that cannot fit one line..."))
            .setPriority(NotificationCompat.PRIORITY_HIGH)

    manager?.notify(456,builder.build())

}

AndroidManifest. XML-файл:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
     calls FlutterMain.startInitialization(this); in its onCreate method.
     In most cases you can leave this as-is, but you if you want to provide
     additional functionality it is fine to subclass or reimplement
     FlutterApplication and put your custom class here. -->
<application
    android:name=".MyApplication"
    android:label="bizzyb_demo"
    android:icon="@mipmap/ic_launcher">
    <service android:name=".MyService" android:exported="true" android:enabled="true"/>

    <activity
        android:name=".MainActivity"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize">
        <!-- This keeps the window background of the activity showing
             until Flutter renders its first frame. It can be removed if
             there is no splash screen (such as the default splash screen
             defined in @style/LaunchTheme). -->
        <meta-data
            android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
            android:value="true" />

        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
        <intent-filter>
            <action android:name="FLUTTER_NOTIFICATION_CLICK" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>

Что я здесь не так делаю. Я считаю, что я упускаю что-то очень очевидное здесь, так как я новичок в разработке мобильных приложений.

Ваши отзывы экспертов будут оценены. Спасибо

1 Ответ

0 голосов
/ 25 октября 2019

Вам необходимо включить click_action: FLUTTER_NOTIFICATION_CLICK в качестве пары ключ-значение «Пользовательские данные» в полезную нагрузку уведомления.

Bundle bundle = new Bundle();
bundle.putString(Constants.EXAM_ID,String.valueOf(lectureDownloadStatus.getExamId()));

var builder = NotificationCompat.Builder(this, "notifications")
            .setOngoing(true)
            .setContentIntent(pendingIntent)
            .setFullScreenIntent(pendingIntent, true)
            .setSmallIcon(R.drawable.common_google_signin_btn_icon_dark)
            .setContentTitle("My notification")
            .setContentText("Much longer text that cannot fit one line...")
            .setStyle(NotificationCompat.BigTextStyle()
            .bigText("Much longer text that cannot fit one line..."))
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setExtras(bundle) // Set the bundle

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...