Issue
I am new to Android.
I embedded Cordova WebView on my Android app by following the tutorial.
I already successfully load a webpage from my server by using CordovaWebView.
Let's say that I have a button on that webPage called "Capture Photo", what should I do to call the local API so that I can use the camera?
The tutorial suggest that I need to implement the CordovaInterface to use camera in the way as follow.
@Override
public void setActivityResultCallback(CordovaPlugin plugin) {
this.activityResultCallback = plugin;
}
I don't know what exactly is activityResultCallback. Is there another tutorial to show me how to implement this interface?
Solution
Since nobody answer my question.
I find a tutorial that can solve this problem.
Update: Given that the link is broken, I'll post my own code for implementing the Cordova Interface.
// Instance for CordovaInterface
private final ExecutorService threadPool = Executors.newCachedThreadPool();
private boolean mAlternateTitle = false;
private boolean bound;
private boolean volumeupBound;
private boolean volumedownBound;
private CordovaPlugin activityResultCallback;
private Object activityResultKeepRunning;
private Object keepRunning;
public Activity getActivity() {
return this;
}
@Deprecated
public Context getContext() {
return this;
}
public ExecutorService getThreadPool() {
return threadPool;
}
public void setActivityResultCallback(CordovaPlugin plugin) {
this.activityResultCallback = plugin;
}
public void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode) {
this.activityResultCallback = command;
this.activityResultKeepRunning = this.keepRunning;
// If multitasking turned on, then disable it for activities that return
// results
if (command != null) {
this.keepRunning = false;
}
// Start activity
super.startActivityForResult(intent, requestCode);
}
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
final CordovaPlugin callback = this.activityResultCallback;
if (callback != null) {
// Need to use background thread
this.getThreadPool().execute(new Runnable() {
public void run() {
callback.onActivityResult(requestCode, resultCode, intent);
}
});
}
}
Answered By - Dragon warrior
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.