
BdvDesigner
1
Ro
Verificación en dos pasos activada
Verificado por Whatsapp
¡Ha verificado su Paypal!
¡Usuario popular!
Suscripción a IA
Chicos estoy trabajando con la app de un cliente (es de acá del foro), resulta que es una webview y el cliente utiliza OneSignal para sus notificaciones push mediante el plugin de wordpress.
Cuando mi cliente publica un post automáticamente el plugin envía la notificación pero ¿que sucede? la notificación llega sin el thumbails del post, todo está configurado a la perfección tanto en el plugin como en Android Studio y soporte de OseSignal no me da una respuesta concreta.
¿Les ha sucedido esto?
Vale resaltar que comúnmente utilizo las push de firebase y nunca me ha pasado esto, puesto que llegan las notificaciones con imágenes a la perfección.
¿Que puede estar fallando?
Les dejo el OnesignalNotifications.java
Cuando mi cliente publica un post automáticamente el plugin envía la notificación pero ¿que sucede? la notificación llega sin el thumbails del post, todo está configurado a la perfección tanto en el plugin como en Android Studio y soporte de OseSignal no me da una respuesta concreta.
¿Les ha sucedido esto?
Vale resaltar que comúnmente utilizo las push de firebase y nunca me ha pasado esto, puesto que llegan las notificaciones con imágenes a la perfección.
¿Que puede estar fallando?
Les dejo el OnesignalNotifications.java
import android.app.Application;
import android.content.Intent;
import com.onesignal.OSNotification;
import com.onesignal.OSNotificationOpenResult;
import com.onesignal.OneSignal;
import com.ovortex.simplewebview.activities.MainActivity;
import com.ovortex.simplewebview.settings.Config;
import org.json.JSONObject;
public class OnesignalNotifications extends Application {
@Override
public void onCreate() {
super.onCreate();
OneSignal.startInit(this)
.setNotificationOpenedHandler(new NotificationHandler())
.autoPromptLocation(true)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.setNotificationReceivedHandler(new NotificationReceivedHandler ())
.init();
OneSignal.idsAvailable(new OneSignal.IdsAvailableHandler() {
@Override
public void idsAvailable(String userId, String registrationId) {
MainActivity.id_onesignal = userId;
}
});
}
// This fires when a notification is opened by tapping on it or one is received while the app is running.
private class NotificationHandler implements OneSignal.NotificationOpenedHandler {
// This fires when a notification is opened by tapping on it.
@Override
public void notificationOpened(OSNotificationOpenResult result) {
try {
JSONObject data = result.notification.payload.additionalData;
final String url_notification = result.notification.payload.launchURL;
String body = result.notification.payload.body;
String title = result.notification.payload.title;
String admobDelay = null;
if (data != null) {admobDelay = data.optString(Config.ADMOB_DELAY_TAG, null);}
if (result.notification.isAppInFocus) {//if app is opened
if(admobDelay != null){
MainActivity.myWebView.loadUrl("javascript:try { Android.setDelayInterstitialJS('"+admobDelay+"'); } catch(err) { }");
}
if(url_notification != null){
MainActivity.myWebView.loadUrl("javascript:try { Android.notificationOnesignalOpenUrlJS('"+title+"','"+body+"','"+url_notification+"'); } catch(err) { }");
}else{
MainActivity.myWebView.loadUrl("javascript:try { Android.alertDataJS('"+title+"','"+body+"'); } catch(err) { }");
}
}else{//if app is closed start the app
Intent intent = new Intent(OnesignalNotifications.this, MainActivity.class);
intent.putExtra("body", String.valueOf(body));
intent.putExtra("title", String.valueOf(title));
if(admobDelay != null){
intent.putExtra(Config.ADMOB_DELAY_TAG, String.valueOf(admobDelay));
}
if(url_notification != null){
if(!url_notification.equals("")){
intent.putExtra(Config.ADMOB_URL_NOTIFICATION_TAG, String.valueOf(url_notification));
}
}
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
} catch (Throwable t) {
t.printStackTrace();
}
}//end notificationOpened
}//end NotificationHandler
private class NotificationReceivedHandler implements OneSignal.NotificationReceivedHandler {
@Override
public void notificationReceived(OSNotification notification) {
//optional use to receive a notification
}
}
}//end OnesignalNotifications
import android.content.Intent;
import com.onesignal.OSNotification;
import com.onesignal.OSNotificationOpenResult;
import com.onesignal.OneSignal;
import com.ovortex.simplewebview.activities.MainActivity;
import com.ovortex.simplewebview.settings.Config;
import org.json.JSONObject;
public class OnesignalNotifications extends Application {
@Override
public void onCreate() {
super.onCreate();
OneSignal.startInit(this)
.setNotificationOpenedHandler(new NotificationHandler())
.autoPromptLocation(true)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.setNotificationReceivedHandler(new NotificationReceivedHandler ())
.init();
OneSignal.idsAvailable(new OneSignal.IdsAvailableHandler() {
@Override
public void idsAvailable(String userId, String registrationId) {
MainActivity.id_onesignal = userId;
}
});
}
// This fires when a notification is opened by tapping on it or one is received while the app is running.
private class NotificationHandler implements OneSignal.NotificationOpenedHandler {
// This fires when a notification is opened by tapping on it.
@Override
public void notificationOpened(OSNotificationOpenResult result) {
try {
JSONObject data = result.notification.payload.additionalData;
final String url_notification = result.notification.payload.launchURL;
String body = result.notification.payload.body;
String title = result.notification.payload.title;
String admobDelay = null;
if (data != null) {admobDelay = data.optString(Config.ADMOB_DELAY_TAG, null);}
if (result.notification.isAppInFocus) {//if app is opened
if(admobDelay != null){
MainActivity.myWebView.loadUrl("javascript:try { Android.setDelayInterstitialJS('"+admobDelay+"'); } catch(err) { }");
}
if(url_notification != null){
MainActivity.myWebView.loadUrl("javascript:try { Android.notificationOnesignalOpenUrlJS('"+title+"','"+body+"','"+url_notification+"'); } catch(err) { }");
}else{
MainActivity.myWebView.loadUrl("javascript:try { Android.alertDataJS('"+title+"','"+body+"'); } catch(err) { }");
}
}else{//if app is closed start the app
Intent intent = new Intent(OnesignalNotifications.this, MainActivity.class);
intent.putExtra("body", String.valueOf(body));
intent.putExtra("title", String.valueOf(title));
if(admobDelay != null){
intent.putExtra(Config.ADMOB_DELAY_TAG, String.valueOf(admobDelay));
}
if(url_notification != null){
if(!url_notification.equals("")){
intent.putExtra(Config.ADMOB_URL_NOTIFICATION_TAG, String.valueOf(url_notification));
}
}
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
} catch (Throwable t) {
t.printStackTrace();
}
}//end notificationOpened
}//end NotificationHandler
private class NotificationReceivedHandler implements OneSignal.NotificationReceivedHandler {
@Override
public void notificationReceived(OSNotification notification) {
//optional use to receive a notification
}
}
}//end OnesignalNotifications