Back to project page Abstack-books-management.
The source code is released under:
MIT License
If you think the Android project Abstack-books-management listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.abstack.book.plugin; /*from w w w.j a v a2 s . c o m*/ import org.apache.cordova.api.CallbackContext; import org.apache.cordova.api.CordovaPlugin; import org.apache.cordova.api.PluginResult; import org.json.JSONArray; import org.json.JSONException; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import com.abstack.book.CaptureActivity; public class CameraPlugin extends CordovaPlugin{ @Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if ("scan".equals(action)) { this.scan(args, callbackContext); } return true; } private void scan(JSONArray args, CallbackContext callbackContext) { Intent openCameraIntent = new Intent(this.cordova.getActivity(),CaptureActivity.class); hand.setCallback(callbackContext); this.cordova.startActivityForResult(this, openCameraIntent, 0); PluginResult mPlugin = new PluginResult(PluginResult.Status.NO_RESULT); mPlugin.setKeepCallback(true); callbackContext.sendPluginResult(mPlugin); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { //???????????????????? if (resultCode == Activity.RESULT_OK) { Bundle bundle = data.getExtras(); final String scanResult = bundle.getString("result"); new Thread(new Runnable(){ @Override public void run() { Message message = new Message(); message.obj = scanResult; message.what = OK; hand.sendMessage(message); } }).start(); } } public final static int OK = 200; @SuppressLint("HandlerLeak") class Hand extends Handler { public CallbackContext callback; public void setCallback(CallbackContext callback) { this.callback = callback; } } private Hand hand = new Hand() { public void handleMessage(Message msg) { Log.wtf("assert", msg.obj.toString()); switch (msg.what) { case OK: if (callback!=null) callback.success("{\"success\": true, \"ISBN\": \""+msg.obj+"\"}"); break; default: if (callback!=null) callback.error("{\"success\": false, \"message\": \"????????\"}"); } }; }; }