Zxing Android - How to get scanner/camera not in fullscreen?

716 views
Skip to first unread message

mlambole

unread,
Dec 11, 2014, 10:04:36 AM12/11/14
to zx...@googlegroups.com
I only recently started developing under android and I like it but yesterday I ran into this problem with zxing and it is driving me crazy and I really can't seem to find a solution. I am using zxing to scan QR codes, it works but the scanner goes fullscreen when I launch it and I would like it to be displayed in one fragment, not take the whole screen. I am developing an app on a tablet with two fragments as below

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:theme="@android:style/Theme.NoTitleBar"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">

<fragment android:name="com.example.mlambole.fragapp.InfoFragment"
android:id="@+id/info_fragment"
android:background="#B89470"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />

<fragment android:name="com.example.mlambole.fragapp.DetailFragment"
android:id="@+id/detail_fragment"
android:background="#ffffff"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="match_parent" />

</LinearLayout>
The class DetailFragment takes 2/3 third of the screen on the right and that is the place where I would like the scanner to show, only in these 2/3.

The DetailFragment class looks like as of now

public class DetailFragment extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.detail_view, container, false);

Button buttonScan = (Button) view.findViewById(R.id.button_scan);
buttonScan.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
clickScan(v);
}
});
return view;
}

public void clickScan(View view)
{

IntentIntegrator integrator = IntentIntegrator.forFragment(this);
integrator.initiateScan(IntentIntegrator.QR_CODE_TYPES);

}

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
System.out.println("onActivityResult");
if (scanResult != null) {
String scanContent = scanResult.getContents();
String scanFormat = scanResult.getFormatName();
}
}

}
The MainActivity

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().hide();
setContentView(R.layout.main_screen);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
I use Android Studio and Zxing with Maven as follow

repositories {
mavenCentral()

maven {
url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/"
}
}

dependencies {
// Supports Android 4.0.3 and later (API level 15)
compile 'com.embarkmobile:zxing-android-minimal:2.0.0@aar'

// Supports Android 2.1 and later (API level 7), but not optimal for later Android versions.
// If you only plan on supporting Android 4.0.3 and up, you don't need to include this.
compile 'com.embarkmobile:zxing-android-legacy:2.0.0@aar'

// Convenience library to launch the scanning and encoding Activities.
// It automatically picks the best scanning library from the above two, depending on the
// Android version and what is available.
compile 'com.embarkmobile:zxing-android-integration:2.0.0@aar'

// Version 3.0.x of zxing core contains some code that is not compatible on Android 2.2 and earlier.
// This mostly affects encoding, but you should test if you plan to support these versions.
// Older versions e.g. 2.2 may also work if you need support for older Android versions.
compile 'com.google.zxing:core:3.0.1'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Is there a zxing genius out there ?? please

Thanks

Issam Harrazi

unread,
Nov 11, 2018, 12:05:02 PM11/11/18
to zxing
bonjour, est ce que vous avez trouvé une solution à votre problème
Merci
Reply all
Reply to author
Forward
0 new messages