資源簡介
這個是我自己寫的cordova的插件。
主要是實現的功能是從本地圖庫選圖片,根據選擇的圖片來判斷是否含有二維碼。
如果有,直接識別并返回信息,如有沒有,會提示圖片格式錯誤。
解壓后,大家可以直接添加到cordova項目里。
在html添加一個按鈕和點擊事件,就可以直接運行了
代碼片段和文件信息
package?com.wy.plugin;
import?android.content.Intent;
import?android.database.Cursor;
import?android.os.Build;
import?android.os.Looper;
import?android.provider.MediaStore;
import?android.widget.Toast;
import?com.google.zxing.Result;
import?org.apache.cordova.CallbackContext;
import?org.apache.cordova.CordovaPlugin;
import?org.json.JSONArray;
import?org.json.JSONException;
import?static?android.app.Activity.RESULT_OK;
public?class?photoImage?extends?CordovaPlugin?{
????private?CallbackContext?mCallbackContext;
????private?int?RESULT_LOAD_IMAGE?=?1;
????private?String?photo_path?=?null;
????private?String?recode?=?null;
????@Override
????public?boolean?execute(String?action?JSONArray?args?CallbackContext?callbackContext)?throws?JSONException?{
????????this.mCallbackContext?=?callbackContext;
????????if?(“getQRImageInfo“.equals(action))?{
????????????getPic();
????????????return?true;
????????}
????????mCallbackContext.error(“error“);
????????return?false;
????}
????/**
?????*?從本地圖庫選圖片
?????*/
????private?void?getPic()?{
????????Intent?innerIntent?=?new?Intent();?//?“android.intent.action.GET_CONTENT“
????????if?(Build.VERSION.SDK_INT?19)?{
????????????innerIntent.setAction(Intent.ACTION_GET_CONTENT);
????????}?else?{
????????????//?innerIntent.setAction(Intent.ACTION_OPEN_DOCUMENT);??這個方法報?圖片地址?空指針;使用下面的方法
????????????innerIntent.setAction(Intent.ACTION_PICK);
????????}
????????innerIntent.setType(“image/*“);
????????Intent?wrapperIntent?=?Intent.createChooser(innerIntent?“選擇二維碼圖片“);
????????cordova.startActivityForResult(this?wrapperIntent?RESULT_LOAD_IMAGE);
????}
????@Override
????public?void?onActivityResult(int?requestCode?int?resultCode?Intent?data)?{
????????super.onActivityResult(requestCode?resultCode?data);
????????if?(requestCode?==?RESULT_LOAD_IMAGE)?{
????????????if?(resultCode?==?RESULT_OK)?{
????????????????String[]?proj?=?{MediaStore.Images.Media.DATA};
????????????????//?獲取選中圖片的路徑
????????????????final?Cursor?cursor?=?cordova.getActivity().getContentResolver().query(data.getData()
????????????????????????proj?null?null?null);
????????????????if?(cursor.moveToFirst())?{
????????????????????int?column_index?=?cursor
????????????????????????????.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
????????????????????photo_path?=?cursor.getString(column_index);
????????????????????if?(photo_path?==?null)?{
????????????????????????photo_path?=?Utils.getPath(cordova.getActivity()
????????????????????????????????data.getData());
????????????????????}
????????????????}
????????????????cursor.close();
????????????????cordova.getThreadPool().execute(new?Runnable()?{
????????????????????public?void?run()?{
????????????????????????Result?result?=?Utils.scanningImage(photo_path);
????????????????????????//?String?result?=?decode(photo_path);
????????????????????????if?(result?==?null)?{
????????????????????????????Looper.prepare();
????????????????????????????Toast.makeText(cordova.getActivity()?“圖片格式有誤
- 上一篇:Echart.rar
- 下一篇:個人主頁html模板 靜態網頁模板
評論
共有 條評論