I have created plugin for background service (to run the application in background) in phonegap .I have created service for run the application in background using android.Then start the service from plugin.In index.html I call that plugin in button click event.When I click the button the service is started.
Is it possible using android service run the javascript in background and get alert from background?how to do that?
Now I want to run the javascript in background.Is it possible how to get alert in background.also need to call the wcf rest service.
please guide me.thanks in advance.
My code in Index.html
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady()
{
alert("hello");
navigator.notification.alert("hai");
}
after starting service My application is run in background.I want this “alert(“hello”);””navigator.notification.alert(“hai”);” in background.(ie) alert found in my .html file.But you give code for activity in android.It should run the javascript in background and display alert from that.please guide me.thanks in advance.I have one more doubt this service also run my wcf rest service in background and diaplay alert from that service. please tell me the solution
My code for service:
public class MyService extends Service {
private static final String TAG = "MyService";
MediaPlayer player;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();
Log.d(TAG, "onCreate");
player = MediaPlayer.create(this, R.raw.braincandy);
player.setLooping(false); // Set looping
}
@Override
public void onDestroy() {
Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();
Log.d(TAG, "onDestroy");
player.stop();
}
@Override
public void onStart(Intent intent, int startid) {
Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
Log.d(TAG, "onStart");
player.start();
Toast.makeText(this, "alert Started", Toast.LENGTH_LONG).show();
}
}
In this code I have add one player.so after starting service .song is played in foreground,song is played, after pressing home button in emulator(background).I want to show alert like this.how to do that?
In my plugin
if (CALL_SERVICE_ACTION.equals(action)) {
Log.d(TAG, "CALL_SERVICE_ACTION");
ctx.startService(new Intent(ctx, MyService.class));
Intent i = new Intent(ctx, AppNotification.class);
ctx.startActivity(i);
}
I have call your activity after starting service It show alert only in fore ground after pressing home button in emulator.the alert not come( from background)please tell me solution
In index.html
function callServiceFunction() {
window.plugins.BackgroundService.callService('callService',
callServiceSuccessCallBack, callServiceFailCallBack);
}
function callServiceSuccessCallBack(e) {
alert("Success");
callNotificationsFunction();
}
function callServiceFailCallBack(f) {
alert("Failure");
}
function callNotificationsFunction() {
window.plugins.BackgroundService.callNotifications('callNotifications',
callNotificationsSuccessCallBack, callNotificationsFailCallBack);
}
function callNotificationsSuccessCallBack(e) {
alert("Success");
}
function callNotificationsFailCallBack(f) {
alert("Failure");
}
while I am clicking background button service created.and It call callNotificationFunction from callservicesuccesscallback.it display alert in foreground.after I am clicking home button in emulator nothing happend, alert not dispalyed from background, please guide me thanks in advance.If I call callNotificationFunction in separate button click nothing happend(alert is not displayed in foreground) and no error in logcat
In order to show alert in your background. Create an Activity which runs as a dialog.
For example create an activity like this
Also In manifest file use this
And Call this activity when ever you want to show some notifications like this
In Order to Give Notifications use
Just as you used service plugin to call the service you use the call notifications.And then perform the actions like this