How to force using zxing lib with only my application?

前端 未结 4 1013
抹茶落季
抹茶落季 2020-12-19 20:20

Ok lets say there are 3 different applications which are using zxing lib on the phone. Whenever I want to open zxing with my own application android asks me whether to compl

相关标签:
4条回答
  • 2020-12-19 20:33

    Actually you need to remove intent-filter like CommonsWare said, so it must be as follows:

    <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">
    </activity>
    

    and instead of calling via external intent you should call zxing like:

    private final static int ACTION_ZXING_SCANNER = 0x0000c0de; //IntentIntegrator.REQUEST_CODE
    private void startZxingScanner() {
        final Intent intent = new Intent(this, com.google.zxing.client.android.CaptureActivity.class);
        intent.setAction(Intents.Scan.ACTION);
        startActivityForResult(intent, ACTION_ZXING_SCANNER);
    }
    

    and then process result in onActivityResult() using request code ACTION_ZXING_SCANNER. The import string if needed:

    import com.google.zxing.client.android.Intents;
    

    note: this works for me and I added zxing project as a lib to my project so here it is - the "zxing lib" :)

    0 讨论(0)
  • 2020-12-19 20:34

    Just include this,this has done the needed for me..

    Intent intent = new Intent("com.google.zxing.client.android.SCAN");
                intent.setPackage(getPackageName());
                intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
                startActivityForResult(intent, 0);
    
    0 讨论(0)
  • 2020-12-19 20:44

    First, there is no "zxing lib". You are supposed to use the Barcode Scanner application, tying it into your application at the activity level, ideally using their IntentIntegrator code. Here is a sample application demonstrating this. The creators of ZXing specifically do not support or endorse baking the Barcode Scanner source code into another application.

    However, given your symptoms, I have to assume that you are trying to add the Barcode Scanner source code to your own application.

    You presumably have something like this in your manifest on the scanning activity's element:

            <intent-filter >
                <action android:name="com.google.zxing.client.android.SCAN" />
    
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
    

    You are not Barcode Scanner. Yet, this <intent-filter> claims that you are Barcode Scanner.

    You need to remove this <intent-filter>, modify your copy of the Barcode Scanner source code to not require it, and then start up the scanning activity using the component-based Intent constructor (e.g., new Intent(this, ThisIsYourRevisedScanningActivity.class)).

    0 讨论(0)
  • 2020-12-19 20:54

    Android does not allow you to set this on your own. Only a user can set the default application for an action. If on your phone, you want your app to handle that event, then check the Use as default box before selecting your app in the picker.

    For security reasons, Android does not allow you to set your app as the default without user interaction as then a malicious app could tie itself as the default to various events.

    0 讨论(0)
提交回复
热议问题