Android - 可以从包裹在PhoneGap中的应用程序触发本机意图 [英] Android - Is it possible to fire a native intent from an application wrapped in PhoneGap
问题描述
我需要捕获并将Sencha Touch中的一个事件触发传输到本机Android环境。
ie:一些sencha touch-controlled-按钮需要点击启动另一个活动(非PhoneGap活动)的意图。
到目前为止,我发现了各种示例,例如网站内容和此。但是据我所知,这些在我的情况下是不适用的。
我试图放弃PhoneGap并与另一个包装器一起工作,或以某种方式规避这个问题。感谢提前!
我想你需要制作自己的phonegap插件,从内部启动本机活动方法。
有一个ContactView插件,您应该可以使用它来编写自己的指南。
https://github.com/phonegap/phonegap-plugins /blob/master/Android/ContactView/ContactView.java
具体来说这两种方法
@Override
public PluginResult execute(String action,JSONArray args,String callbackId){
startContactActivity();
PluginResult mPlugin = new PluginResult(PluginResult.Status.NO_RESULT);
mPlugin.setKeepCallback(true);
this.callback = callbackId;
return mPlugin;
}
public void startContactActivity(){
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
this.ctx.startActivityForResult((Plugin)this,intent,PICK_CONTACT);
}
I am developing an application on Sencha Touch 2.0.1 & PhoneGap.
I need to catch and transfer an event firing inside Sencha Touch to the native Android environment.
i.e: Some sencha touch-controlled-buttons need to fire an intent on click to start another activity (non-PhoneGap activities).
So far I have found various examples like webintents and this. But as far as I see, these are inapplicable in my case.
I seek to either drop PhoneGap and work with another wrapper, or somehow circumvent this issue. Thanks in advance!
I think you'll need to make your own phonegap plugin that launches the native activity from inside it's execute method.
There's a ContactView plugin you should be able to use as a guide for writing your own.
https://github.com/phonegap/phonegap-plugins/blob/master/Android/ContactView/ContactView.java
Specifically these two methods
@Override
public PluginResult execute(String action, JSONArray args, String callbackId) {
startContactActivity();
PluginResult mPlugin = new PluginResult(PluginResult.Status.NO_RESULT);
mPlugin.setKeepCallback(true);
this.callback = callbackId;
return mPlugin;
}
public void startContactActivity() {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
this.ctx.startActivityForResult((Plugin) this, intent, PICK_CONTACT);
}
这篇关于Android - 可以从包裹在PhoneGap中的应用程序触发本机意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!