2016-04-14 152 views
0

當我掃描條碼的Android斑馬線庫

enter image description here

我得到這個resultScan

enter image description here

,但我想這個內容的結果,以檢測它是否包含短信或電子郵件以這種方式發送消息,例如,如果此內容包含電子郵件消息,則需要打開電子郵件窗口,並且我想填寫字段,例如:使用此電子郵件,也使用主題和正文。

我的代碼,到現在爲止是:

public void onActivityResult(int requestCode, int resultCode, Intent intent) { 
    IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent); 
    String content = intent.getStringExtra("SCAN_RESULT"); 
} 
+0

你可以把你的內容串上分號的基礎上,讓您的單獨消息 –

+0

分開束值,如果你在那裏找到的電子郵件,然後發送電子郵件其他SMS –

+0

維韋克·米什拉,如果我的身體 – Ges

回答

-1

我掃描QR碼,並得到這些原始的文字: 「MATMSG:TO:[email protected]; SUB:你好; BODY:hdfukfhdksu ;;」。通過Android操作

public static EmailSendObject parseQrcodeText(String rawText){ 
     //todo parse; 
     EmailSendObject.recipent;//should be "[email protected]" 
     EmailSendObject.subject;//should be "hello" 
     EmailSendObject.cc; 
     EmailSendObject.content;//should be "hdfukfhdksu;" 
     return EmailSendObject; 
    } 

步驟2.發送電子郵件: 「ACTION_SENDTO」

步驟1.You應解析Schema得到EmailSendObject如下面。

public static void sendEmail(Activity activity,EmailSendObject object){ 
    Uri uri = Uri.parse("mailto:"+object.recipient); 
    Intent intent = new Intent(Intent.ACTION_SENDTO, uri); 
    intent.putExtra(Intent.EXTRA_CC, object.cc); 
    intent.putExtra(Intent.EXTRA_SUBJECT, object.subject); 
    intent.putExtra(Intent.EXTRA_TEXT, object.content); 
    activity.startActivity(Intent.createChooser(intent, "Choose a email app!")); 
} 
+0

再次閱讀問題和評論:**我的問題是如何獲取條形碼的類型,如文本,網址,地址簿,電話號碼,電子郵件地址。**這與電子郵件意圖無關。 –

+0

EmailSendObject無法識別,我應該創建一個類 – Ges

+0

識別這些類型的結果(文本,URL,地址簿,電話號碼,電子郵件地址),它依賴於schema.No方式自動檢測!您應該解析它一個one.My答案是如何解析電子郵件文本和發送電子郵件。 – banking

2

您需要仔細檢查電子郵件地址是否有多於一個,在本例中我只考慮了一封電子郵件。如果你看到email.getTos()方法,你會看到這是一個String []。

public void onActivityResult(int requestCode, int resultCode, Intent intent) { 
    IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent); 

    Result res = new Result(scanResult.getContents(), null, null, BarcodeFormat.QR_CODE); 
    ParsedResult parserdResult = ResultParser.parseResult(res); 

    Log.d("GORIO", "TYPE: " + parserdResult.getType().toString()); 

    switch (parserdResult.getType()) { 
     case ADDRESSBOOK: 
      Log.d("GORIO", "ADDRESSBOOK: " + parserdResult.getDisplayResult()); 
      break; 
     case EMAIL_ADDRESS: 
      Log.d("GORIO", "EMAIL_ADDRESS: " + parserdResult.getDisplayResult()); 
      EmailAddressParsedResult email = (EmailAddressParsedResult) parserdResult; 

      if (email.getTos().length > 0) 
       Log.d("GORIO", "E-mail: " + email.getTos()[0] + " Subject: " + email.getSubject() + " Body: " + email.getBody()); 
      break; 
     case PRODUCT: 
      ProductParsedResult prod = (ProductParsedResult) parserdResult; 
      Log.d("GORIO", "PRODUCT: " + scanResult.getContents()); 
      break; 
     case URI: 
      URIParsedResult uri = (URIParsedResult) parserdResult; 
      Log.d("GORIO", "URI: " + scanResult.getContents()); 
      break; 
     case GEO: 
      GeoParsedResult geo = (GeoParsedResult) parserdResult; 
      Log.d("GORIO", "GEO: " + scanResult.getContents()); 
      break; 
     case TEL: 
      TelParsedResult tel = (TelParsedResult) parserdResult; 
      Log.d("GORIO", "TEL: " + scanResult.getContents()); 
      break; 
     case SMS: 
      Log.d("GORIO", "SMS: " + scanResult.getContents()); 
      SMSParsedResult sms = (SMSParsedResult) parserdResult; 
      Log.d("GORIO", "SMS: " + sms.getNumbers()); 
      break; 
     case CALENDAR: 
      Log.d("GORIO", "CALENDAR: " + scanResult.getContents()); 
      break; 
     case ISBN: 
      ISBNParsedResult isbn = (ISBNParsedResult) parserdResult; 
      Log.d("GORIO", "ISBN: " + scanResult.getContents()); 
      break; 
     default: 
    } 
} 
+0

非常感謝你@Gorio,這對我很有幫助 – Ges

+0

非常感謝你@Gorio,這對我很有幫助 –