Want to develop a QR code reader.. which will customized for my application. after a lot of search i found a link http://www.androidaz.com/development/zxing-qr-reader-direct-integration this tutorial demonstrate what i exactly want. but when i import it and then run this app i notice that its camera is in 90 degree angle when i rotate device. what is the problem i can not realize. my main.xml is
<FrameLayout
android:layout_width="200dip"
android:layout_height="200dip"
android:layout_gravity="center_horizontal">
<include layout="#layout/capture"/>
</FrameLayout>
my mainactivity file is:
public class ScannerActivity extends CaptureActivity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_qrcode);
}
#Override
public void handleDecode(Result rawResult, Bitmap barcode)
{
Toast.makeText(this.getApplicationContext(), "Scanned code " + rawResult.getText(), Toast.LENGTH_LONG).show();
}
}
menifest file with permission :
<uses-permissionandroid:name="android.permission.CAMERA"/>
<uses-permissionandroid:name="android.permission.INTERNET"/>
<uses-permissionandroid:name="android.permission.VIBRATE"/>
<uses-permissionandroid:name="android.permission.FLASHLIGHT"/>
<uses-permissionandroid:name="android.permission.READ_CONTACTS"/>
<uses-permissionandroid:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permissionandroid:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permissionandroid:name="android.permission.ACCESS_WIFI_STATE"/>
it can read QR code fine. only problem camera caused abnormal behavior when rotating..
Thanks in advanced.
Maybe what you would like to do is here:
android-zxinglib
An android library project of zxing BarcodeScanner
https://code.google.com/p/android-zxinglib/
Download the project and look these files:
AndroidManifest.xml
capture.xml
Go into your manifest and change the orientation to landscape. Portrait caused the same problem for me, and landscape looked a lot better.
Related
I am new to android development and I am working on an android project where I have to integrate QR scanner. So I thought I would integrate Zxing QR scanner and came across this library https://github.com/dm77/barcodescanner, Following the instructions provided I have successfully integrated and scanned a QR as well.
Now I want to customise the camera view. The problem is there is no documentation on how to get access to the camera layout. Since I am new I might be missing something.
I have read through many Zxing related threads but I din find any solution.
Any help will be greatly appreciated either by letting me know on how I can get access to the camera view or pointing me out to some articles. Once I know how then I can complete the rest.
I would be happy to provide any further information.
Thanks in advance.
Update:
public class QrScanActivity extends BaseActivity implements ZXingScannerView.ResultHandler {
private ZXingScannerView mScannerView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_scan);
// Programmatically initialize the scanner view
mScannerView = new ZXingScannerView(this);
// Set the scanner view as the content view
setContentView(mScannerView);
}
mScannerView is the view from the library. I want to get access to that view. I have a view called as activity_my_scan. I can add custom layout to that and use that but I don't know how to bypass the layout being used by the library.
Instead of just adding this lib as a jar using gradle's
compile 'me.dm7.barcodescanner:zxing:1.6.3'
you could clone the project from github or download a zip and uzip it and integrate to your project as a lib project. And then make any desired changes in its sources and its layouts.
ZXingScannerView extends BarcodeScannerView. You can access this by going to the declaration of ZXingScannerView (in Android Studio Ctrl+B).
public class ZXingScannerView extends BarcodeScannerView {
private MultiFormatReader mMultiFormatReader;
public static final List<BarcodeFormat> ALL_FORMATS = new ArrayList();
private List<BarcodeFormat> mFormats;
private ZXingScannerView.ResultHandler mResultHandler;
If you go the declaration of BarcodeScannerView, you'll notice a method called setupLayout() which formats the layout:
public void setupLayout() {
this.mPreview = new CameraPreview(this.getContext());
this.mViewFinderView = new ViewFinderView(this.getContext());
RelativeLayout relativeLayout = new RelativeLayout(this.getContext());
relativeLayout.setGravity(17);
relativeLayout.setBackgroundColor(-16777216);
relativeLayout.addView(this.mPreview);
this.addView(relativeLayout);
this.addView(this.mViewFinderView);
}
By going to the declaration of "CameraPreview" you'll be able to get more info for how the camera is laid out and you could maybe extend ZXingScannerView to edit the layout.
Hope this helps!
Cheers!
Well in your case i would try to include the layout into another layout, maybe it helps:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:background="#color/app_bg"
android:gravity="center_horizontal">
<include layout="#layout/titlebar"/>
<TextView android:layout_width=”match_parent”
android:layout_height="wrap_content"
android:text="#string/hello"
android:padding="10dp" />
...
</LinearLayout>
And of course there is information about that here ;)
This question already has answers here:
How do I make a splash screen? [closed]
(31 answers)
Closed 8 years ago.
Okay so what I'm wanting to do is add an image to my splash screen, so it displays the image before the app starts. I think(?) I found the right code to actually do the splash screen but I can't get the image in it. From what I've read it needs to be in a png file, which it is but how do I move it from a file on my computer to the code, and then where do I go from there?
Assuming that you have exactly the code given in How do I make a splash screen? then you simply need to save your picture as splash.png in the app/main/src/res/drawable folder. Be sure to clean and rebuild your project before running it. Note that you can give the PNG any name you want. Just change splash in android:src="#drawable/splash" to match the name you use. Also, I strongly encourage you to learn about the directory structure in an Android Studio project.
My post here answers this question.
To "move" the image from a file to your code, you need to place it into your drawable folder, then refrence it somewhere by using
#drawable/image
To better understand how to change the splash screen image please read below.
Add Splash Screen Image
First you need a splash screen image. Because Android devices come in
various resolutions, you may want to ship several splash screens as
described in Google's Best Practices for Supporting Multiple Screens.
For simplicity, we'll just ship one here that is 480x800. It should
support most phone sizes pretty well, and Android will scale it as
best it can.
Add the the image/gif you want into your Resources\Drawable
You need to define the splash screen in your layout.xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView id="#+id/splashscreen" android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="#drawable/splash"
android:layout_gravity="center"/>
<TextView android:layout_width="fill_parent" <!-- Not needed->-->
android:layout_height="wrap_content"
android:text="Hello World, splash"/> <!--Not Needed -->
</LinearLayout>
And your activity:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class Splash extends Activity {
/** Duration of wait **/
private final int SPLASH_DISPLAY_LENGTH = 1000;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.splashscreen);
/* New Handler to start the Menu-Activity
* and close this Splash-Screen after some seconds.*/
new Handler().postDelayed(new Runnable(){
#Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(Splash.this,Menu.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}, SPLASH_DISPLAY_LENGTH);
}
}
I am using Scringo for implementing Group Chat within my Android App. Is there a way in which we can open a particular chatroom through code ? Right now, from the sample applications and API, I found only the below code.
Scringo.openChatRooms(MainActivity.this);
Please let me know how do I
Create a Chatroom programmatically
Open a particular Chatroom programmatically.
Right now Scringo SDK is not providing way to open a chatroom programmatically. They are having their own screens(Activity) to manage the many to many Chat functionality. They are yet to integrate the following features on their Android SDK.
1. Creating Chatrooms programmatically
2. Joining/Opening Chatrooms programmatically
Source: I got a response from their Support Team. They claim that this feature is available for their IOS sdk. I am not sure.
This code solved my problem :
MainActivity.java
public class MainActivity extends Activity {
private Scringo scringo;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
scringo = new Scringo(this);
...
findViewById(R.id.openChatRoomButton).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Scringo.openChatRooms(MainActivity.this);
}
});
...
}
main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
...
<Button
android:id="#+id/openChatRoomButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:text="#string/open_inbox_button_text" />
</RelativeLayout>
I'm struggling with a memory leak issue at Google Maps Android API v2. The heap usage increases by about 85KB every time my view becomes visible again after:
Phone screen turns off (eg after pressing the power button).
The user exits the app pressing the Home button.
The app eventually crashes with an OutOfMemory exception. The leak does NOT occur on screen rotate, or when exiting by "back" button. Any ideas about a workaround or the reason behind this problem?
My code:
public class LeakActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_leak);
}
}
and the XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/myLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="#+id/map_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
This might be related to this open issue in the Maps API:
Issue 4766 - Bug: Android Maps API v2 leaks huge amounts of memory
Use DDMS' "Dump HPROF" tool to dump a hprof file, convert it with hprof-conv and use MAT to examine the leak. If it's in Google Maps API, please post an apk (or better simple test code) to the open issue and include the hprof file.
If it is the same bug I am experiencing, it might only happen on Android 2.x, please check that too.
I tried to use System.gc() and map.clear() before the map is initialized.
#Override
public void onActivityCreated (Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()) == ConnectionResult.SUCCESS) {
System.gc();
getMap().clear();
setupmap();
}
}
#Override
public void onLowMemory() {
super.onLowMemory();
System.gc();
}
I'm new at this. Go easy.
My code so far looks like this.
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.hardware.Camera;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String fmode = "Not Supported";
Camera cam = Camera.open();
Camera.Parameters p = cam.getParameters();
if (p.getFlashMode() != null)
{fmode = p.getFlashMode();}
TextView tv = new TextView(this);
tv.setText(fmode);
setContentView(tv);
}
}
When I run the program, I get the message stating that The application has stopped unexpectedly. Please try again. If I comment out these four lines...
//Camera cam = Camera.open();
//Camera.Parameters p = cam.getParameters();
//if (p.getFlashMode() != null)
//{fmode = p.getFlashMode();}
then the code runs fine and I get the "Not Supported" message. Then if I uncomment the first line where I declare the Camera object, it crashes again.
Feel free to be verbose, I'm in learning mode and would like all the information I can get. Thanks in advance.
Any chance you missed adding the camera permission in your AndroidManifest?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<application ...>
.
.
.
</application>
</manifest>
If that's not the case:
Why does the android emulator camera stop unexpectedly?
I'm not very familiar using a camera in apps but I found you a great tutorial that can help you on your way towards your solution.
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html
I hope this is helpful for you and may you find what you need :) if not, I'll make a test app myself and help you further
And like someone else stated above, some permissions must be added to use the camera, you can find those here:
http://developer.android.com/reference/android/hardware/Camera.html
Permissions are needed to allow access to certain features in android. Did you put <uses-permission android:name="android.permission.CAMERA" /> in your android manifest to have access to the camera.