4
4
import android .graphics .Bitmap ;
5
5
import android .graphics .BitmapFactory ;
6
6
import android .os .AsyncTask ;
7
+ import android .os .Build ;
8
+ import android .os .VibrationEffect ;
9
+ import android .os .Vibrator ;
7
10
8
11
import com .google .zxing .BarcodeFormat ;
9
12
import com .google .zxing .BinaryBitmap ;
34
37
import io .flutter .plugin .common .MethodChannel .Result ;
35
38
import io .flutter .plugin .common .PluginRegistry .Registrar ;
36
39
40
+ import static android .content .Context .VIBRATOR_SERVICE ;
41
+
37
42
/** ScanPlugin */
38
43
public class ScanPlugin implements FlutterPlugin , MethodCallHandler , ActivityAware {
39
44
private MethodChannel channel ;
@@ -113,7 +118,7 @@ public QrCodeAsyncTask(ScanPlugin plugin, String path) {
113
118
@ Override
114
119
protected String doInBackground (String ... strings ) {
115
120
// 解析二维码/条码
116
- return QRCodeDecoder .syncDecodeQRCode ( path );
121
+ return QRCodeDecoder .decodeQRCode ( mWeakReference . get (). flutterPluginBinding . getApplicationContext (), path );
117
122
}
118
123
119
124
@ Override
@@ -124,6 +129,16 @@ protected void onPostExecute(String s) {
124
129
plugin ._result .success (s );
125
130
plugin .task .cancel (true );
126
131
plugin .task = null ;
132
+ if (s !=null ) {
133
+ Vibrator myVib = (Vibrator ) plugin .flutterPluginBinding .getApplicationContext ().getSystemService (VIBRATOR_SERVICE );
134
+ if (myVib != null ) {
135
+ if (Build .VERSION .SDK_INT >= 26 ) {
136
+ myVib .vibrate (VibrationEffect .createOneShot (50 , VibrationEffect .DEFAULT_AMPLITUDE ));
137
+ } else {
138
+ myVib .vibrate (50 );
139
+ }
140
+ }
141
+ }
127
142
}
128
143
}
129
144
}
0 commit comments