2012-07-04 53 views
0

我的phonegap應用程序使用zxing條碼掃描器。我aso從zxing安裝一個演示程序(barcodescanner)。現在,在我的phonegap應用程序中,當我打電話給條碼掃描器時,android問我選擇哪個應用程序來執行此操作(我的應用程序和zxing barcodescanner)。如何避免這種情況?我不希望android問我這樣的用戶android intent call without inquiry

回答

0

如果您還沒有更改任何代碼,默認情況下Zxing註冊以下意圖。

<action android:name="com.phonegap.plugins.barcodescanner.SCAN" /> 

您可以通過執行以下更改來更改此選項,以使其更具體。

// in BarcodeScanner.java plugin file 

public void scan() { 
    // changed to custom intent 
    Intent intentScan = new Intent("com.dhaval.phonegap.plugins.barcodescanner.SCAN"); 
    intentScan.addCategory(Intent.CATEGORY_DEFAULT); 

    this.ctx.startActivityForResult((Plugin) this, intentScan, REQUEST_CODE); 
} 


public void encode(String type, String data) { 
    // changed to custom intent 
    Intent intentEncode = new Intent("com.dhaval.phonegap.plugins.barcodescanner.ENCODE"); 
    intentEncode.putExtra("ENCODE_TYPE", type); 
    intentEncode.putExtra("ENCODE_DATA", data); 

    this.ctx.startActivity(intentEncode); 
} 

在你的應用程序AndroidManifest.xml文件,意圖過濾字符串更改爲BarcodeScanner.java使用您的自定義字符串文件之上

<activity android:name="com.google.zxing.client.android.CaptureActivity" 
      android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden" 
      android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
      android:windowSoftInputMode="stateAlwaysHidden"> 
      <intent-filter> 
       <action android:name="com.dhaval.phonegap.plugins.barcodescanner.SCAN" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
     </activity> 
     <activity android:name="com.google.zxing.client.android.encode.EncodeActivity" 
      android:label="@string/share_name"> 
      <intent-filter> 
       <action android:name="com.dhaval.phonegap.plugins.barcodescanner.ENCODE" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
     </activity> 
+0

對於任何遇到同樣問題的人,我都做了 - 還有一個地方需要重新命名 - 在LibraryProject中,轉到src/com/google/zxing/client/android/Intents.java尋找「public static final String ACTION「並將其更改爲新的intent名稱。 – Matt

0

您可以撥打setPackage()Intent您發送給指揮它只有一個可能的應用程序。在這裏你可以設置爲"com.google.zxing.client.android"