I have just purchased DS premium
And write code the code work full on DS Environment
I'm using latest DS 5.77 and I also tried 2.76 latest apkbuilder as well.
But when I build apk then show black and show
Web page not available
net::ERR_CACHE_MISS
And when I run the code on DS ENVIRONMENT then work fully
Here are my codes:
Main.js
// MainApp.js
var svc = null, txtStatus = null; // Service handle and text control
function OnStart() {
// Create a vertical layout to hold controls.
var lay = app.CreateLayout("linear", "VCenter,FillXY");
// Create a Text control to display messages from the service.
txtStatus = app.CreateText("Waiting for service message...", 0.8, 0.1);
lay.AddChild(txtStatus);
// Create a button to send the "change" message to the service.
var btnChange = app.CreateButton("Send 'change'", 0.6, 0.1);
btnChange.SetOnTouch(btnChange_OnTouch);
lay.AddChild(btnChange);
// Create a button to stop the service.
var btnStop = app.CreateButton("Stop Service", 0.6, 0.1);
btnStop.SetOnTouch(btnStop_OnTouch);
lay.AddChild(btnStop);
// Add the layout to the app UI.
app.AddLayout(lay);
// Start/connect to the background service. OnServiceReady is called when ready.
svc = app.CreateService("this", "this", OnServiceReady);
// Register callback for messages from the service.
svc.SetOnMessage(OnServiceMessage);
}
function OnServiceReady() {
// Called when the service has started. We can show a notification if needed.
app.ShowPopup("Service started");
}
function btnChange_OnTouch() {
if (svc) {
// Send the "change" message to the service.
svc.SendMessage("change");
}
}
function btnStop_OnTouch() {
if (svc) {
// Stop the background service.
svc.Stop();
app.ShowPopup("Service stopped");
}
}
function OnServiceMessage(msg) {
// Display the incoming message from the service in the text control.
txtStatus.SetText("Service says: " + msg);
}
Service.js
// Service.js
// Global state
var g_ = {
counter: 0,
direction: 1,
interval: null,
notify: null
};
// Called when the service starts
function OnStart()
{
// Put service in foreground (for Android 8+)
app.SetInForeground("Counter Service", "Service is running", "", "", "high");
// Create notification listener
g_.notify = app.CreateNotification();
g_.notify.SetOnNotify(notify_OnNotify);
g_.notify.Listen();
// Start periodic work: call DoWork every second
g_.interval = setInterval(DoWork, 1000);
}
// Periodic task: update counter and send to main app
function DoWork()
{
g_.counter += g_.direction;
app.SendMessage(g_.counter);
}
// Handle messages from the main app
function OnMessage(msg)
{
console.log("Service received message: " + msg);
if (msg == "change") {
// Change counting direction
g_.direction *= -1;
}
}
// Handle received notifications
// Parameters may be: (packageName, title, text, id) depending on implementation
function notify_OnNotify(title, text)
{
// Show popup when a notification is received
var message = "Notification received: " + title;
if (text) message += " - " + text;
app.ShowPopup(message);
}
// Clean up when service stops
function OnStop()
{
if (g_.interval) {
clearInterval(g_.interval);
g_.interval = null;
}
if (g_.notify) {
g_.notify.Release();
g_.notify = null;
}
}
Here is the errors msg: