Cordova 加载自定义url后跳转继续在本页面中加载

1。新建本地自定义插件MyCordovaPlugin

package com.test.helloworld;

import org.apache.cordova.CordovaPlugin;

public class MyCordovaPlugin extends CordovaPlugin {

    @Override
    public Boolean shouldAllowRequest(String url) {
        // TODO Auto-generated method stub
        return true;
    }

    @Override
    public Boolean shouldAllowNavigation(String url) {
        // TODO Auto-generated method stub
        return true;
    }

}

2。config.xml中配置插件

...... <feature name="MyCordovaPlugin"> <param name="android-package" value="com.test.helloworld.MyCordovaPlugin" /> <param name="onload" value="true" /> </feature> ......

3.activity中加载网址

/*
       Licensed to the Apache Software Foundation (ASF) under one
       or more contributor license agreements.  See the NOTICE file
       distributed with this work for additional information
       regarding copyright ownership.  The ASF licenses this file
       to you under the Apache License, Version 2.0 (the
       "License"); you may not use this file except in compliance
       with the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing,
       software distributed under the License is distributed on an
       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
       KIND, either express or implied.  See the License for the
       specific language governing permissions and limitations
       under the License.
 */

package com.test.helloworld;

import android.app.ActionBar.OnNavigationListener;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import org.apache.cordova.*;

public class MainActivity extends CordovaActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Set by <content src="index.html" /> in config.xml
        // loadUrl(launchUrl);
        loadUrl("http://m.xxx.com.cn/");

    }

}

你可能感兴趣的:(Cordova,插件,PhoneGap)