跨平臺(tái)的跳轉(zhuǎn)Activity android插件調(diào)用原生

首先繼承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通過(guò)intent傳值:http://www.itdecent.cn/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

。。。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容