2017-06-29 40 views
0

我目前正在使用Visual Studio開發Xamarin,嘗試構建並創建一個應用程序,該應用程序讀取條形碼並將它從它獲取的整數保存在.txt文件中。我設法使代碼都讀取條形碼並保存它,但是我想知道是否有辦法將它保存在一個更易訪問的文件中,因爲現在它保存在內部存儲器中,並且是我可以訪問它的唯一方法是通過adb控制檯。 有沒有一種方法可以將我的筆記本電腦上的.txt文件保存爲整數?我目前正在使用我的物理電話測試它,並通過USB電纜將其連接到筆記本電腦。Xamarin在Visual Studio上的外部存儲

這裏是我的代碼:

using Android.App; 
using Android.Widget; 
using Android.OS; 
using System; 
using Android.Content; 
using ZXing.Mobile; 
using System.IO; 

namespace Scanner 
{ 
    [Activity(Label = "Scanner", MainLauncher = true, Icon = "@drawable/icon")] 
    public class MainActivity : Activity 
    { 
     protected override void OnCreate(Bundle bundle) 
     { 
      base.OnCreate(bundle); 

      // Set our view from the "main" layout resource 
      SetContentView (Resource.Layout.Main); 
      Button buttonScan = FindViewById<Button>(Resource.Id.buttonScan); 
      TextView scanText = FindViewById<TextView>(Resource.Id.scanText); 
      var documents = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); 
      var BarcodesFile = Path.Combine(documents, "Barcodes.txt"); 
      buttonScan.Click += async (sender, e) => 
      { 
       MobileBarcodeScanner.Initialize(Application); 
       var scanner = new ZXing.Mobile.MobileBarcodeScanner(); 
       var result = await scanner.Scan(); 

       if (result != null) 
        File.AppendAllText(BarcodesFile, "Scanned Barcode: " + result.Text); 
        scanText.Text = File.ReadAllText(BarcodesFile); 
      }; 
     } 

    } 
} 
+0

正在與外部數據庫或互聯網上的文件可能是一個選項?有適當的一些API的網站,你可以寫在一個TXT文件 –

+0

這實際上可以工作。我不知道那些存在,但我現在會檢查出來。謝謝:) – Dan

回答

0

所以,如果API是一個想法。我還沒有使用任何api但這些要求,但是當我想到txt時,我立即想到了pastebin。

https://pastebin.com/apienter code here

這可能是有用的,檢查出來。 Goodluck !;)

+0

就像我認爲pastebin是一個好主意,我想我寧願將它保存在桌面上的文件上。但我會嘗試。 – Dan

+0

也許尋找像谷歌驅動器,一個驅動器的api。而且,您可以將計算機與其中一個驅動器同步? –

+0

但是我有沒有辦法通過筆記本電腦訪問手機中的內部文件? – Dan