PockyBridge provides a seamless interface between Android Native components and WebView. Access device hardware, system UI, and Firebase data through a unified JavaScript object.
To enable the bridge, the Android application must register the interface within the WebView setup. Ensure the Pocky object is ready on the web side to receive events.
// Android side
webView.addJavascriptInterface(new PockyBridge(this, webView), "Pocky");
Utilize the Pocky object to interact with Native features seamlessly.
Retrieve authenticated user data fetched from Firebase.
Pocky.getUserName(): Returns current user's name.Pocky.getUserEmail(): Returns current user's email.Pocky.addNewCard(jsonString): Saves a new card.Pocky.deleteCardByID(cardId): Deletes a card by ID.Pocky.archiveCardByID(cardId): Archives a card.Pocky.getAllCards(): Returns JSON array of all cards.Pocky.updateList(jsonArray): Refreshes native Android list.
JSON Handling: All complex data (Arrays/Objects) must be passed as JSON strings. Ensure window.Pocky is initialized early to avoid missing events.
Define these functions within your window.Pocky object to handle Native → Web events.
| Event | Description |
|---|---|
| OnDialogPositive | User clicked "Positive" button. |
| OnDialogNegative | User clicked "Negative" button. |
| OnNewCardAdded | Broadcasts new card data. |
| OnCardDeleted | Broadcasts successful removal. |
Example: Handling a Confirmation Dialog
// 1. Trigger the dialog
Pocky.showDialog("confirm_delete_01", "Delete this item?", "Delete", "Cancel");
// 2. Listen for the choice
window.Pocky = {
...window.Pocky,
OnDialogPositive: function(data) {
const response = JSON.parse(data);
if (response.id === "confirm_delete_01") {
Pocky.vibrate(100);
}
}
};
Example: Syncing Data to Native UI
const myCards = [{ name: "Personal ID", id: "001" }];
Pocky.updateList(JSON.stringify(myCards));