• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

App Inventor How to send variable from php to Android Webview?

Hi! thanks in advance for taking the time to help me :)

few days ago I’ve purchased a codecanyon webview framework, made with Kotlin, it is really a great framework since it helped me to turn my website into a real app (I only know how to develope on php & mysql, not java lol)

And the framework has integrated the OneSignal & Firebase push notifications service…

To this point all is working really great… but I wan’t to level up my project to a new step, and send user-specific push notifications (Ex. Someone post on your profile)

I know that I can take advantage of OneSignal Tags to add a tag for every OneSignal subscribed user with my website userid… but the problem is that I don´t know how to take that $_SESSION[“userid”] from my php website and use it on my Android Webview App to create the OneSignal tag for the current user…

In my Android files, I have a file called OnesignalMessagingService.kt with this information:

`package name...

import android.app.Application
import android.content.Context
import android.content.Intent
import android.util.Log
import com.onesignal.OSNotification
import com.onesignal.OSNotificationAction
import com.onesignal.OSNotificationOpenResult
import com.onesignal.OneSignal
import infix.imrankst1221.codecanyon.MainActivity

class OnesignalMessagingService: Application() {
val TAG = "---Onesignal"
lateinit var mContext: Context

override fun onCreate() {
super.onCreate()
mContext = this
OneSignal.startInit(this)
.setNotificationOpenedHandler(NotificationHandler())
.autoPromptLocation(true)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.setNotificationReceivedHandler(NotificationReceivedHandler())
.init()

OneSignal.idsAvailable { userId, registrationId -> Log.d("", ""+userId) }
}


inner class NotificationHandler : OneSignal.NotificationOpenedHandler {
// This fires when a notification is opened by tapping on it.
override fun notificationOpened(result: OSNotificationOpenResult) {
val actionType = result.action.type
val data = result.notification.payload.additionalData
val customKey: String?

if (data != null) {
customKey = data.optString("url", null)
if (customKey != null) {
AppDataInstance.getINSTANCE(mContext)
AppDataInstance.notificationUrl = customKey
AppDataInstance.isOpenOutside = data.optBoolean("is_open_outside", false)
Log.i(TAG, "Link set with value: $customKey")
}
}

if (actionType == OSNotificationAction.ActionType.ActionTaken)
Log.i(TAG, "Button pressed with id: " + result.action.actionID)

val intent = Intent(applicationContext, MainActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_REORDER_TO_FRONT or Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(intent)
}
}

private inner class NotificationReceivedHandler : OneSignal.NotificationReceivedHandler {
override fun notificationReceived(notification: OSNotification) {
// receive a notification
}
}
}`

How I can add this code to create the tag for the current user:

`OneSignal.sendTag("userId", "1");`

And how to change userid “1” with my current $_SESSION[“userid”] from the php weview website

I don´t know if it is helpfull but I’ve created a json file with the current session id:

https://tribbr.me/api/json/get_sessionid.php (it only echo information if you are logged in into my website): (Ej. https://jmp.sh/fdMQtdG )

Thanks for your help, I’m really new in Android developing, but with a big desire to learn new stuff every day :)
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones