android res/xml/config.xml
<feature name="XXXPlugin">
<param name="android-package" value="com.yyy.plugins.XXXPlugin"/>
</feature>
android src/com/yyy/plugins/XXXPlugin.java
此插件的作用是跳转到微信APP上。
package com.smbc.plugins;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import org.json.JSONArray;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.util.Log;
import android.content.Context;
import android.content.Intent;
public class XXXPlugin extends CordovaPlugin{
private final String pluginName = "XXXPlugin";
@Override
public boolean execute(final String action, final JSONArray data, final CallbackContext callbackContext) {
boolean result = false;
this.show(data, callbackContext);
result = true;
return result;
}
public synchronized void show(final JSONArray data, final CallbackContext callbackContext) {
Context currentCtx = cordova.getActivity();
try {
PackageManager packageManager = currentCtx.getPackageManager();
Intent intent = new Intent();
intent = packageManager.getLaunchIntentForPackage("com.tencent.mm");
currentCtx.startActivity(intent);
callbackContext.success("success");
} catch (Exception e) {
e.printStackTrace();
Intent viewIntent = new
Intent("android.intent.action.VIEW", Uri.parse("http://weixin.qq.com/"));
currentCtx.startActivity(viewIntent);
callbackContext.error("error");
}
}
}
GotoApp.js
var GotoApp = function() {
};
GotoApp.prototype.show= function(options,callback, errorCallback) {
var defaults = {
};
console.log('Invoke Plugin!');
utility.invokePlugin(//不都这么写。。。
"GotoAppPlugin",
'showApp',
[defaults],
callback,
errorCallback
);
}
在HTML里写一个按钮 点击后跳转到微信APP 方法名是 jumpToApp
ctrl里这么写
$scope.jumpToApp=function(){
var options = {
};
var gotoApp = new GotoApp();
gotoApp.show(options,onSuccess,onError);
}
function onSuccess(success){
alert(success);
}
function onError(error){
alert(error);
}
index.html里需要配置下
<script src="js/plugins/GotoApp.js"></script>