首先繼承CordovaPlugin
重寫execute方法? ? execute返回值為true時(shí)? 此插件可用;返回為false時(shí) 此插件失效
在插件類當(dāng)中獲取? this 跳轉(zhuǎn)
Intent intent = new Intent(cordova.getActivity(), DemoActivity.class);
cordova.startActivityForResult((CordovaPlugin) this,intent, 200);
如果使用
cordova.getActivity().startActivityForResult(intent,200);
被調(diào)用的Activity 在? setResult之后;
并不會(huì)返回到當(dāng)前的插件中? 它將返回到的webView的CordovaActivity當(dāng)中 ,
Plugin_intent 類的? onActivityResult將收不到消息? ? ;
我查看源碼后得知? ? cordova這個(gè)是CordovaInterface類型的? 已由CordovaPlugin實(shí)現(xiàn)
在CordovaInterface當(dāng)中找到了
/**
* 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.reibang.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
抵卫。。坦弟。