首先继承CordovaPlugin
重写execute方法 execute返回值为true时 此插件可用;返回为false时 此插件失效
在插件类当中获取 this 跳转
Intent intent = new Intent(cordova.getActivity(), DemoActivity.class);
cordova.startActivityForResult((CordovaPlugin) this,intent, 200);
如果使用
cordova.getActivity().startActivityForResult(intent,200);
被调用的Activity 在 setResult之后;
并不会返回到当前的插件中 它将返回到的webView的CordovaActivity当中 ,
Plugin_intent 类的 onActivityResult将收不到消息 ;
我查看源码后得知 cordova这个是CordovaInterface类型的 已由CordovaPlugin实现
在CordovaInterface当中找到了
/**
* Launch an activity for which you would like a result when it finished. When this activity exits,
* your onActivityResult() method will be called.
*
* @param command The command object
* @param intent The intent to start
* @param requestCode The request code that is passed to callback to identify the activity
*/
abstract public void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode);
利用Android通过intent传值:http://www.jianshu.com/p/8a45e87f2aca
综合代码得:
CDVImageProcessing.java
public class CDVImageProcessing extends CordovaPlugin{
privateCallbackContextcCtx;
public booleanexecute(String action,CordovaArgs args,
CallbackContext callbackContext)throwsJSONException {
cCtx= callbackContext;
if(action.compareTo("cut") ==0) {//图片剪裁
String urlSrc;
JSONObject jobject_asp = args.getJSONObject(0);
if(jobject_asp.getString("sourceType").equals("URL")){//获取要剪裁的图片类型
urlSrc = jobject_asp.getString("sourceImageSrc");
}else{
urlSrc ="";
}
Intent intent =newIntent(cordova.getActivity(),cutimgactivity.class);
intent.putExtra("imgUrl",urlSrc);
cordova.startActivityForResult((CordovaPlugin)this,intent,200);
}
return true;
}
}
cutimgactivity.java
protected voidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cutimgactivity);
imageView= (ImageView) findViewById(R.id.imgView);
Intent intent=getIntent(); //获得intent
。。。
网友评论