I just recently started developing under android, and I like it, but yesterday I ran into this problem with zxing, and it drives me crazy, and I really can't find a solution. I use zxing to scan QR codes, it works, but the scanner goes into full-screen mode when I run it, and I would like it to be displayed in one fragment, not the whole screen. I am developing an application on a tablet with two fragments, as shown 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 DetailFragment class occupies 2/3 of the third screen on the right, and this is the place where I would like to show the scanner only in these 2/3.
The DetailFragment class looks like 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();
}
}
}
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) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
I am using Android Studio and Zxing with Maven, as follows
repositories {
mavenCentral()
maven {
url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/"
}
}
dependencies {
compile 'com.embarkmobile:zxing-android-minimal:2.0.0@aar'
compile 'com.embarkmobile:zxing-android-legacy:2.0.0@aar'
compile 'com.embarkmobile:zxing-android-integration:2.0.0@aar'
compile 'com.google.zxing:core:3.0.1'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Is there a zxing genius? you are welcome
thank