Skip to main content
se eliminaron 30 caracteres en el cuerpo
Origen Enlace
Ivan Alfredo
  • 909
  • 3
  • 24
  • 42
public class MyFirebaseMessagingService extends FirebaseMessagingService {

public String notificacion;

public static final String TAG = "NOTICIAS";

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    if (remoteMessage.getData().size() > 0) {

    }
    if (remoteMessage.getNotification() != null) {
        mostrarNotificacion(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());

    }
}

private void mostrarNotificacion(String title, String body) {

    //Intent intent = new Intent(this, MainActivity.class);
    Intent intent = new Intent(this, PushActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(title)
            .setContentText(body)
            .setAutoCancel(true)
            .setSound(soundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notificationBuilder.build());

    /*
    Log.d(TAG, "fari"+ body);
    notificacion = body;
    Intent i = new Intent(this, PushActivity.class);
    i.putExtra("ms", notificacion);
    startActivity(i);
    */
}
}
public class PushActivity extends AppCompatActivity {

private static final String TAG = "ivan";
public TextView tx_push;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_push);

    tx_push = (TextView) findViewById(R.id.push_id);

    //String msm = getIntent().getExtras().getString("ms");
    //tx_push.setText(msm);
    //Log.d(TAG, "ivan"+ msm);

}
}

Tengo este error introducir la descripción de la imagen aquí

public class MyFirebaseMessagingService extends FirebaseMessagingService {

public String notificacion;

public static final String TAG = "NOTICIAS";

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    if (remoteMessage.getData().size() > 0) {

    }
    if (remoteMessage.getNotification() != null) {
        mostrarNotificacion(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());

    }
}

private void mostrarNotificacion(String title, String body) {

    //Intent intent = new Intent(this, MainActivity.class);
    Intent intent = new Intent(this, PushActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(title)
            .setContentText(body)
            .setAutoCancel(true)
            .setSound(soundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notificationBuilder.build());

    /*
    Log.d(TAG, "fari"+ body);
    notificacion = body;
    Intent i = new Intent(this, PushActivity.class);
    i.putExtra("ms", notificacion);
    startActivity(i);
    */
}
}
public class PushActivity extends AppCompatActivity {

private static final String TAG = "ivan";
public TextView tx_push;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_push);

    tx_push = (TextView) findViewById(R.id.push_id);

    //String msm = getIntent().getExtras().getString("ms");
    //tx_push.setText(msm);
    //Log.d(TAG, "ivan"+ msm);

}
}
public class MyFirebaseMessagingService extends FirebaseMessagingService {

public String notificacion;

public static final String TAG = "NOTICIAS";

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    if (remoteMessage.getData().size() > 0) {

    }
    if (remoteMessage.getNotification() != null) {
        mostrarNotificacion(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());

    }
}

private void mostrarNotificacion(String title, String body) {

    //Intent intent = new Intent(this, MainActivity.class);
    Intent intent = new Intent(this, PushActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(title)
            .setContentText(body)
            .setAutoCancel(true)
            .setSound(soundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notificationBuilder.build());

    Log.d(TAG, "fari"+ body);
    notificacion = body;
    Intent i = new Intent(this, PushActivity.class);
    i.putExtra("ms", notificacion);
    startActivity(i);
}
}
public class PushActivity extends AppCompatActivity {

private static final String TAG = "ivan";
public TextView tx_push;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_push);

    tx_push = (TextView) findViewById(R.id.push_id);

    String msm = getIntent().getExtras().getString("ms");
    tx_push.setText(msm);
    Log.d(TAG, "ivan"+ msm);

}
}

Tengo este error introducir la descripción de la imagen aquí

se eliminaron 1123 caracteres en el cuerpo
Origen Enlace
Ivan Alfredo
  • 909
  • 3
  • 24
  • 42
public class MyFirebaseMessagingService extends FirebaseMessagingService {

public String notificacion;

public static final String TAG = "NOTICIAS";
//String nota_push;
String type;

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    if (remoteMessage.getData().size() > 0) {
        type = "json";
        sendNotificatio(remoteMessage.getData().toString());
    }
    if (remoteMessage.getNotification() != null) {
        type = "message";
        mostrarNotificacion(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());
        sendNotificatio(remoteMessage.getNotification().getBody());

    }
}

private void mostrarNotificacion(String title, String body) {

    //Intent intent = new Intent(this, MainActivity.class);
    //Aqui intento seleccionar la actividad que se abre con el push
    Intent intent = new Intent(this, PushActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(title)
            .setContentText(body)
            .setAutoCancel(true)
            .setSound(soundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notificationBuilder.build());

}

private void sendNotificatio(String messageBody) {
    String id = "";
    String message = "";
    String titles = "";

    if (type.equals("json")) {
        try {
            JSONObject jsonObject = new JSONObject(messageBody);/*
            id = jsonObjectLog.getStringd("id");
            messageTAG, ="fari"+ jsonObject.getString("message"body);
            titlesnotificacion = jsonObject.getString("title");

            //aquí envío el String a la la otra actividadbody;
            Intent i = new Intent(this, PushActivity.class);
            i.putExtra("ms", messagenotificacion);
            startActivity(i);

        } catch (JSONException e) {
            e.printStackTrace();
        }

    } else if (type.equals("message")) {
        message = messageBody;
    }
*/
}
}
public class PushActivity extends AppCompatActivity {

private static final String TAG = "ivan";
public TextView tx_push;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_push);
 
    String msm = getIntent().getExtras().getString("ms");
    tx_push = (TextView) findViewById(R.id.push_id);
    tx_push.setText(msm);
    Log.d(TAG, "ivan"+ msm);
    /*
    Bundle/String parametrosmsm = this.getIntent().getExtras();
    if(parametros !=null){
        String datos = parametros.getString("ms");
        //tx_push.setText(datosmsm);
        //Log.d(TAG, "ivan"+ datosmsm);
 
    }
    */
    }
}
}
public class MyFirebaseMessagingService extends FirebaseMessagingService {

public static final String TAG = "NOTICIAS";
//String nota_push;
String type;

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    if (remoteMessage.getData().size() > 0) {
        type = "json";
        sendNotificatio(remoteMessage.getData().toString());
    }
    if (remoteMessage.getNotification() != null) {
        type = "message";
        mostrarNotificacion(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());
        sendNotificatio(remoteMessage.getNotification().getBody());

    }
}

private void mostrarNotificacion(String title, String body) {

    //Intent intent = new Intent(this, MainActivity.class);
    //Aqui intento seleccionar la actividad que se abre con el push
    Intent intent = new Intent(this, PushActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(title)
            .setContentText(body)
            .setAutoCancel(true)
            .setSound(soundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notificationBuilder.build());

}

private void sendNotificatio(String messageBody) {
    String id = "";
    String message = "";
    String titles = "";

    if (type.equals("json")) {
        try {
            JSONObject jsonObject = new JSONObject(messageBody);
            id = jsonObject.getString("id");
            message = jsonObject.getString("message");
            titles = jsonObject.getString("title");

            //aquí envío el String a la la otra actividad
            Intent i = new Intent(this, PushActivity.class);
            i.putExtra("ms", message);
            startActivity(i);

        } catch (JSONException e) {
            e.printStackTrace();
        }

    } else if (type.equals("message")) {
        message = messageBody;
    }

}
}
public class PushActivity extends AppCompatActivity {

public TextView tx_push;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_push);
 
    String msm = getIntent().getExtras().getString("ms");
    tx_push = (TextView) findViewById(R.id.push_id);
    tx_push.setText(msm);
    Log.d(TAG, "ivan"+ msm);
    /*
    Bundle parametros = this.getIntent().getExtras();
    if(parametros !=null){
        String datos = parametros.getString("ms");
        tx_push.setText(datos);
        Log.d(TAG, "ivan"+ datos);
 
    }
    */
    }
}
}
public class MyFirebaseMessagingService extends FirebaseMessagingService {

public String notificacion;

public static final String TAG = "NOTICIAS";

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    if (remoteMessage.getData().size() > 0) {

    }
    if (remoteMessage.getNotification() != null) {
        mostrarNotificacion(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());

    }
}

private void mostrarNotificacion(String title, String body) {

    //Intent intent = new Intent(this, MainActivity.class);
    Intent intent = new Intent(this, PushActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(title)
            .setContentText(body)
            .setAutoCancel(true)
            .setSound(soundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notificationBuilder.build());

    /*
    Log.d(TAG, "fari"+ body);
    notificacion = body;
    Intent i = new Intent(this, PushActivity.class);
    i.putExtra("ms", notificacion);
    startActivity(i);
    */
}
}
public class PushActivity extends AppCompatActivity {

private static final String TAG = "ivan";
public TextView tx_push;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_push);

    tx_push = (TextView) findViewById(R.id.push_id);

    //String msm = getIntent().getExtras().getString("ms");
    //tx_push.setText(msm);
    //Log.d(TAG, "ivan"+ msm);

}
}
se añadieron 205 caracteres en el cuerpo
Origen Enlace
Ivan Alfredo
  • 909
  • 3
  • 24
  • 42
public class PushActivity extends AppCompatActivity {

public TextView tx_push;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_push);

    String msm = getIntent().getExtras().getString("ms");
    tx_push = (TextView) findViewById(R.id.push_id);
    tx_push.setText(msm);
    Log.d(TAG, "ivan"+ msm);
    /*
    Bundle parametros = this.getIntent().getExtras();
    if(parametros !=null){
        String datos = parametros.getString("ms");
        tx_push.setText(datos);
        Log.d(TAG, "ivan"+ datos);

    }
    */
    }
}
}
public class PushActivity extends AppCompatActivity {

public TextView tx_push;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_push);

    tx_push = (TextView) findViewById(R.id.push_id);
    Bundle parametros = this.getIntent().getExtras();
    if(parametros !=null){
        String datos = parametros.getString("ms");
        tx_push.setText(datos);
    }
}
}
public class PushActivity extends AppCompatActivity {

public TextView tx_push;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_push);

    String msm = getIntent().getExtras().getString("ms");
    tx_push = (TextView) findViewById(R.id.push_id);
    tx_push.setText(msm);
    Log.d(TAG, "ivan"+ msm);
    /*
    Bundle parametros = this.getIntent().getExtras();
    if(parametros !=null){
        String datos = parametros.getString("ms");
        tx_push.setText(datos);
        Log.d(TAG, "ivan"+ datos);

    }
    */
    }
}
}
Origen Enlace
Ivan Alfredo
  • 909
  • 3
  • 24
  • 42
Loading