Невозможно открыть ожидающее намерение из push-уведомления Android, нет звука и вибрации при отправке push-уведомления - PullRequest
0 голосов
/ 23 января 2019

Я пытаюсь отправить push-уведомление с консоли Firebase, я написал следующий код и создал следующий класс для получения push-уведомления, я получаю push-уведомление, но проблема в том, что мы получаем его без звука или вибрации,Это также не открывает ожидающее намерение, что у нас есть пропуск к построителю уведомлений.Ниже приведен код, который я написал:

В манифесте

<service
            android:name="yourvoicematters.in.yourvoicematters.notifications.MyFirebaseMessagingService"
            android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
        </service>
        <service android:name="yourvoicematters.in.yourvoicematters.notifications.MyFirebaseInstanceIDService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>

В MyFirebaseMessagingService

@Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        //You should use an actual ID instead
        int notificationId = new Random().nextInt(60000);

        Intent intent = new Intent(getApplicationContext(), MainActivity.class); // Here pass your activity where you want to redirect.
        intent.putExtra("From", "notifyFrag");
        intent.putExtra("base_url", "http://aaa.com");

        //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        PendingIntent contentIntent = PendingIntent.getActivity(this, (int) (Math.random() * 100), intent, PendingIntent.FLAG_UPDATE_CURRENT);

        /*
        Intent likeIntent = new Intent(this,LikeService.class);
        likeIntent.putExtra(NOTIFICATION_ID_EXTRA,notificationId);
        likeIntent.putExtra(IMAGE_URL_EXTRA,remoteMessage.getData().get("image-url"));
        PendingIntent likePendingIntent = PendingIntent.getService(this,
                notificationId+1,likeIntent, PendingIntent.FLAG_ONE_SHOT);
        */
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            setupChannels();
        }

        NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(this, ADMIN_CHANNEL_ID)
                        //.setLargeIcon(bitmap)
                        .setSmallIcon(R.mipmap.ic_launcher)
                        .setContentTitle(remoteMessage.getData().get("title"))
                        /*.setStyle(new NotificationCompat.BigPictureStyle()
                                .setSummaryText(remoteMessage.getData().get("message"))
                                .bigPicture(bitmap))/*Notification with Image*/
                        .setContentText(remoteMessage.getData().get("message"))
                        .setAutoCancel(true)
                        .setSound(defaultSoundUri)
                        .setContentIntent(contentIntent);

        notificationManager.notify(notificationId, notificationBuilder.build());

    }

@RequiresApi(api = Build.VERSION_CODES.O)
    private void setupChannels() {
        CharSequence adminChannelName = getString(R.string.notifications_admin_channel_name);
        String adminChannelDescription = getString(R.string.notifications_admin_channel_description);

        NotificationChannel adminChannel;
        adminChannel = new NotificationChannel(ADMIN_CHANNEL_ID, adminChannelName, NotificationManager.IMPORTANCE_LOW);
        adminChannel.setDescription(adminChannelDescription);
        adminChannel.enableLights(true);
        adminChannel.setLightColor(Color.RED);
        adminChannel.enableVibration(true);
        if (notificationManager != null) {
            notificationManager.createNotificationChannel(adminChannel);
        }
    }

В MyFirebaseInstanceIDService

public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {

    private static final String TAG = "MyFirebaseIIDService";

    @Override
    public void onTokenRefresh() {
        // Get updated InstanceID token.
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG, "Refreshed token: " + refreshedToken);

        // If you want to send messages to this application instance or
        // manage this apps subscription on the server side, send the
        // Instance ID token to your app server.
        SharedPreferences preferences =
                PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        preferences.edit().putString(Constants.FIREBASE_TOKEN, refreshedToken).apply();
    }

Две проблемы, с которыми я сталкиваюсь: 1. Уведомления принимаются, но нет звука или вибрации в полученном уведомлении.2. При щелчке уведомления ожидающее намерение не вызывается.3. Я уже использовал android: exported = "true" в манифесте для основного действия

Я уже использовал android: exported = "true" в манифесте для основного действия Я уже включил звуковой код по умолчанию в код.

Мой Мото должен: Получение push-уведомлений со звуком.Открытие в ожидании намерения на уведомлении нажмите

...