Olá Pessoal,
Depois de uns 30 dias tentando e pesquisando, resolvi jogar a toalha e pedir ajuda aos universitários.
Eu tenho uma simples WebView, só quero fazer com que a URL que envio do OneSignal seja aberta nessa WebView. Ela abre, mas abre na página principal e não na URL que enviei.
Lá no OneSignal estou enviando os dados via “Additional Data”, assim: ‘data’ => array(“openURL” => $meuLink).
public class ApplicationClass extends Application {
@Override
public void onCreate() {
super.onCreate();
OneSignal.startInit(this)
.setNotificationOpenedHandler(new ExampleNotificationOpenedHandler())
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.unsubscribeWhenNotificationsAreDisabled(true)
.init();
}
private class ExampleNotificationOpenedHandler implements OneSignal.NotificationOpenedHandler {
// This fires when a notification is opened by tapping on it.
@Override
public void notificationOpened(OSNotificationOpenResult result) {
OSNotificationAction.ActionType actionType = result.action.type;
JSONObject data = result.notification.payload.additionalData;
String launchUrl = result.notification.payload.launchURL; // update docs launchUrl
String openURL = null;
Object activityToLaunch = MainActivity.class;
if (data != null) {
openURL = data.optString("openURL", null);
}
// The following can be used to open an Activity of your choice.
// Replace - getApplicationContext() - with any Android Context.
// Intent intent = new Intent(getApplicationContext(), YourActivity.class);
Intent intent = new Intent(getApplicationContext(), (Class<?>) activityToLaunch);
// intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("openURL", openURL);
// startActivity(intent);
startActivity(intent);
// Add the following to your AndroidManifest.xml to prevent the launching of your main Activity
// if you are calling startActivity above.
/*
<application ...>
<meta-data android:name="com.onesignal.NotificationOpened.DEFAULT" android:value="DISABLE" />
</application>
*/
}
}
}
E na minha MainActivity estou chamando assim:
String url = getIntent().getStringExtra(“openURL”);
if (url == null)
myWebView.loadUrl(uri.toString());
else
myWebView.loadUrl(url);
Simplesmente não consigo receber o openURL na minha MainActivity