2014-06-19 250 views
0

如何將我的應用程序設置爲默認值。像我已經使一個包含QR碼掃描器功能的應用程序一樣,我已經使用了QR碼掃描器的ZXing庫項目。 這是工作文件,但是當我運行項目,我從「使用」選項完成操作。當我點擊我的應用程序掃描儀按鈕時,它會打開設備相機,但在此之前它會詢問選項。我希望我的應用程序是QR掃描儀的默認設置。意味着它不會出現使用選項的完整操作。將應用程序設置爲默認設置android

那麼我該如何做到這一點?在清單

+0

您只須打開斑馬線的應用程序,而不是讓應用程序打開它,如果你點擊你的應用程序的掃描儀按鈕的用戶,請我理解正確嗎? – tknell

+0

@tknell - 你說得對。但ZXing是我的圖書館項目,它不是我的原始應用程序,我的原始應用程序是'ScanQR',我想打開'ScanQR'應用程序,不要詢問用戶打開哪個應用程序 – PTech

+0

好,在您的ScanQR應用程序中,您有一個掃描按鈕,這應該打開一個掃描活動,這也是在ScanQR應用程序?或者你是否想從另一個同樣來自你的活動中打開ScanQR應用程序? – tknell

回答

0

使用意圖過濾來指定動作在活動處理象下面這樣:

<activity class=".NoteEditor" android:label="@string/title_note"> 

     <intent-filter android:label="@string/resolve_edit"> 
      <action android:name="android.intent.action.VIEW" /> 
      <action android:name="android.intent.action.EDIT" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <data android:mimeType="vnd.android.cursor.item/vnd.google.note" /> 
     </intent-filter> 

     <intent-filter> 
      <action android:name="android.intent.action.INSERT" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" /> 
     </intent-filter> 

    </activity> 

例如動作名稱讀取QR碼也許android.intent.readQR您指定意圖過濾器這個動作,告訴機器人,你的應用程序處理此行動。當你做得對,你的應用程序應該出現在該列表中。

看看這個鏈接:

http://developer.android.com/reference/android/content/Intent.html

編輯:檢查此鏈接用於設置應用程序爲默認:

http://droidyue.com/blog/2014/01/12/set-the-preferred-application-in-android/

+0

我不希望我的應用程序在列表中,我希望我的應用程序將默認的一個。意味着它被設置爲默認值,所以沒有列表可以打開應用程序。 – PTech

0

如果您已包括斑馬線應用項目( https://github.com/zxing/zxing/tree/master/android),而不僅僅是核心,您可以直接打開負責掃描的活動,如下所示:

Intent intent = new Intent(this,CaptureActivity.class); 
intent.setAction(Intents.Scan.ACTION); 
//or intent.setAction("com.google.zxing.client.android.SCAN"); 
intent.putExtra("SCAN_MODE","QR_CODE_MODE"): // for only scanning qr codes 
startActivityForResult(intent, 9000); // replace 9000 with some request code you defined 

並得到結果在你的活動onActivityResult

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    if (resultCode == RESULT_OK) { 
     if(resultCode=9000){ // again, replace 
      String result = data.getStringExtra("SCAN_RESULT"); 
      ... 
     } 
    } 
相關問題