在Cordova 3.3.0中调用loadUrl

时间:2014-02-22 22:07:57

标签: android plugins cordova call

我试图从服务调用函数“loadUrl”但没有实现它的工作

服务是:

MyService.java

package com.yournamespace.yourappname;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.exam.probando.PROBANDO;

import com.red_folder.phonegap.plugin.backgroundservice.BackgroundService;

public class MyService extends BackgroundService {

    private final static String TAG = MyService.class.getSimpleName();

    private String mHelloTo = "World";

    @Override
    protected JSONObject doWork() {
        JSONObject result = new JSONObject();

        try {
            SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); 
            String now = df.format(new Date(System.currentTimeMillis())); 

            String msg = "Hello " + this.mHelloTo + " - its currently " + now;
            result.put("Message", msg);

            //HERE CALL LoadUrl

            Log.d(TAG, msg);
        } catch (JSONException e) {
        }

        return result;  
    }

    @Override
    protected JSONObject getConfig() {
        JSONObject result = new JSONObject();

        try {
            result.put("HelloTo", this.mHelloTo);
        } catch (JSONException e) {
        }

        return result;
    }

    @Override
    protected void setConfig(JSONObject config) {
        try {
            if (config.has("HelloTo"))
                this.mHelloTo = config.getString("HelloTo");
        } catch (JSONException e) {
        }

    }     

    @Override
    protected JSONObject initialiseLatestResult() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    protected void onTimerEnabled() {
        // TODO Auto-generated method stub

    }

    @Override
    protected void onTimerDisabled() {
        // TODO Auto-generated method stub

    }


}

我尝试使用MainActivity(PROBANDO):

package com.exam.probando;

import android.os.Bundle;
import org.apache.cordova.*;

public class PROBANDO extends CordovaActivity 
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.init();
        // Set by <content src="index.html" /> in config.xml
        super.loadUrl(Config.getStartUrl());
        //super.loadUrl("file:///android_asset/www/index.html");
    }
    public void mainLoadUrl() {
        String url = "file:///android_asset/www/index2.html";
        super.loadUrl(url);
    }
}

但不知道如何打电话给这个..

该插件为:https://github.com/Red-Folder/Cordova-Plugin-BackgroundService/tree/master/3.1.0

问候!

PS:抱歉我的英文不好......

1 个答案:

答案 0 :(得分:0)

您需要通过意图启动活动

Intent intent = new Intent(this, PROBANDO.class);
startActivity(intent);

活动需要在您的清单文件以及服务