|
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);
|
}
|
}
|
|
|
}
|