wxr
2024-08-27 bfb3d0d4879dca8c59ff287c92f5113162f3a33a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Com.Google.Zxing.Integration.Android;
 
namespace HDL_ON_Android
{
    [Activity(Label = "ScanActivity")]
    public class ScanActivity : Activity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
 
            // Create your application here
 
 
 
            IntentIntegrator intentIntegrator = new IntentIntegrator(this);
            intentIntegrator.SetCaptureActivity(Java.Lang.Class.FromType(typeof(HDL_ON_Android.CustomCaptureActivity)));
            intentIntegrator.SetOrientationLocked(false);
            intentIntegrator.SetPrompt("");
            intentIntegrator.InitiateScan();
 
        }
 
        protected override void OnRestart()
        {
            base.OnRestart();
            Finish();
        }
 
 
 
 
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            // 获取解析结果
            IntentResult result = IntentIntegrator.ParseActivityResult(requestCode, (int)resultCode, data);
            if (result != null)
            {
                if (result.Contents != null)
                {
#if DEBUG
                    Console.WriteLine("二维码扫描结果:" + result.Contents);
#endif
                    if(scanResult != null)
                    {
                        scanResult.onResult(result.Contents);
                    }
                }
            }
            else
            {
                base.OnActivityResult(requestCode, resultCode, data);
            }
        }
 
        public static ScanResult scanResult;
 
        public static void InitDdd(ScanResult sr)
        {
            scanResult = sr;
        }
 
        public interface ScanResult
        {
            void onResult(string result);
        }
    }
 
 
}