我已经在phonegap中为后台服务(在后台运行应用程序)创建了插件。我已经创建了使用android在后台运行应用程序的服务。然后从plugin启动服务。在index.html中,我将该插件称为button点击事件。当我点击按钮时,服务启动。 是否有可能使用android服务在后台运行javascript并从后台获取警报?怎么做? 现在我想在后台运行javascript.Is它可能如何获得后台alert.also需要调用wcf rest服务。如何在后台运行javascript?
请提前指导我。
我的index.html中
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady()
{
alert("hello");
navigator.notification.alert("hai");
}
代码开始我的应用程序在运行background.I服务后,希望这个 “警报(” 你好 “);” “navigator.notification.alert(” 辞海“) ;” (ie)在我的.html文件中发现警报。但是你给android中的活动提供代码。它应该在后台运行javascript并显示alert.please引导我。提前感谢。我还有一个疑问服务还在后台运行我的wcf rest服务,并从该服务运行diaplay警报。请告诉我解决 我的服务代码:
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();
}
}
在这段代码我开始服务。宋在前台播放完毕后添加一个player.so,歌曲播放,在模拟器按home键(背景后)。我想要显示像这样的警报如何做到这一点?
在我的插件
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);
}
我打电话开始服役。它显示emulator.the警报按下home键后,只在地面脱颖而出警报不来(从背景)后您的活动,请告诉我解决
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");
}
当我点击背景按钮服务created.and它调用callservicesuccesscallback.it呼叫callNotificationFunction在前景显示警报。我点击模拟器中的主页按钮什么都没发生,警报不显示从背景,请提前引导我感谢。如果我打电话callNotificationFunction在单独的按钮中单击没有任何发生(警报不显示在前景中)并且logcat中没有错误
什么时候你想给通知?当服务启动或通知是动态的时候? – 2012-02-27 07:38:59
当我点击按钮我的服务开始。然后我应该得到前景和背景的警报。(在我的index.html警报)例如:警报(“你好”)和我的WCF休息服务也运行在background.please指南我。在此先感谢您 – Mercy 2012-02-27 08:07:52