Нажмите ручку на кнопку уведомления обрезки и покажите Facebook ShareDialog - PullRequest
0 голосов
/ 06 июля 2018

Я пытаюсь открыть диалоговое окно «Поделиться по умолчанию» на Facebook с помощью пользовательского представления уведомлений Firebase в моем приложении для Android. Я создал кнопку в уведомлении, чтобы открыть диалоговое окно Facebook Share.

Я зарегистрировал широковещательный приемник по действию кнопки в пользовательском представлении уведомлений. При получении получателя вызывается действие, которое в свою очередь покажет Facebook ShareDialog.

Я сделал следующее, чтобы сделать пользовательское уведомление и обработать его действия:

public MyFirebaseMessagingService() {
        serviceContext = this;
    }



    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);

        serviceContext = this;

        String id = remoteMessage.getData().get("tag");
        String click_action = remoteMessage.getNotification().getClickAction();
        try {
            JSONObject jobj;
            jobj=new JSONObject(remoteMessage.getNotification().getBody());
            sendPushNotification(jobj);
        } catch (Exception ex) {
            ex.getMessage();
        }

    }
private void sendPushNotification(JSONObject json) {

    try {
        tag= (String) json.get("tag");
        //some code removed from here which was getting keys from notification body

       //todo qr image through pass code
        WindowManager manager = (WindowManager) this.getSystemService(WINDOW_SERVICE);
        Display display = manager.getDefaultDisplay();
        Point point = new Point();
        display.getSize(point);
        int width = point.x;
        int height = point.y;
        int smallerDimension = width < height ? width : height;
        smallerDimension = smallerDimension * 2/4;
        QRCodeEncoder qrCodeEncoder=new QRCodeEncoder(pass_code,null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(),smallerDimension);
        try {

             bitmap = qrCodeEncoder.encodeAsBitmap();

           // imageQR.setImageBitmap(bitmap);

        } catch (Exception e)
        {
            e.printStackTrace();
        }
        Intent share = new Intent();

        PendingIntent pd1=PendingIntent.getService(this,0,share,0);

        RemoteViews bigview = new RemoteViews(getApplication().getPackageName(), R.layout.notification_view);

        Notification.Builder mnotifybuilder = new Notification.Builder(this);
        foregroundNote = mnotifybuilder.setContentTitle("XYZ")
                .setContentText(message)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setLargeIcon(bitmap)
                .setStyle(new Notification.BigPictureStyle().setSummaryText(message))
                .setAutoCancel(true)
                .setContentIntent(pd1)
                . build();
        foregroundNote.bigContentView = bigview;
        NotificationManager mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        //todo this intent call when button is clicked
        Intent sharepost=new Intent( this,sharebuttonlistner.class);
        Intent deailshow=new Intent(this,deatilbuttonlistner.class);

       PendingIntent pendingshareintent=PendingIntent.getBroadcast(this,0,sharepost,0);
        PendingIntent pendingdetailintent=PendingIntent.getBroadcast(this,0,deailshow,0);
        bigview.setOnClickPendingIntent(R.id.share,pendingshareintent);


        bigview.setOnClickPendingIntent(R.id.details,pendingdetailintent);
        Log.e("share clicked","");


        mNotifyManager.notify(1, foregroundNote);


        //todo remove end

    }
    catch (Exception ex)
    {

        ex.getMessage();
    }
}

Мой широковещательный приемник:

 public static class sharebuttonlistner extends BroadcastReceiver
    {

        public  sharebuttonlistner(){

        }


        @Override
        public void onReceive(Context context, Intent intent) {
            Log.e("on receive call","on receive in receiver");
          

            context.sendBroadcast(new Intent("NOTIFICATION_RECEIVED_FB_POST").putExtra("image_url",image_url));

          Intent i=new Intent(serviceContext,ShowFBShareDialogActivity.class);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            i.putExtra("image_url",image_url);
            serviceContext.startActivity(i);


        }
    }

При нажатии на кнопку в уведомлении вызывается получатель, но не вызывается метод Activity () Activity, при котором я вызываю Facebook ShareDialog.

Пожалуйста, предложите мне решение.

Спасибо.

...