Reputation: 49
I am creating a qr code reader application and I took help from the zXing resource and after running my application on my phone it says "Found URL" and does not redirect me to the specific link of the qr code. It takes me back to my main activity. My project name is "scan" and I have added the core.jar file. I also have one layout page i.e main.xml with a button named "scan qr code" and the activity name is "ScanActvity.java" the whole coding of my project is as:
ScanActivity.java
package com.scan.qr;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class ScanActivity extends Activity {
/** Called when the activity is first created. */
Button btnScan;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnScan = (Button) findViewById(R.id.button1);
btnScan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/button1"
android:layout_width="150dp"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Scan qr code" />
</RelativeLayout>
</LinearLayout>
ActivityMainfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.scan.qr"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".ScanActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<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="android.intent.action.MAIN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
</manifest>
I have also added a folder "zcore" containing core.jar file in my project named "scan" and have added it in the properties i.e under "JavaBuildPath" added jar file named "core.jar" located in "zcore" folder of my project.
Now i tried to run this on emulator it gives me error message like these:
AndroidRuntime(401): at
com.google.zxing.client.android.camera.CameraManager.getFramingRectInPreview
(CameraManager.java:218)
AndroidRuntime(401): at
com.google.zxing.client.android.ViewfinderView.onDraw(ViewfinderView.java:117)
AndroidRuntime(401): at
com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1830)
dalvikvm(401): Unable to open stack trace file '/data/anr/traces.txt': Permission
denied
and then I tried to run the apk file on my samsung galaxy y phone, it runs fine and when I click the button "scan qr code" it opens the camera and when I put image of qr code in front of camera it detects the qr code and reads it and says "Found URL" and then the main page opens up again and it does not redirects me to the specific URL. How can I figure how it will redirect me and show me the information of the qt code? Why doesn't it redirect me to the URL and why does it open the main page again after scanning a qr code?
Please help me out how to solve this problem! Is their anything wrong I did or is there anything to do while making an qr code reader and also please suggest me how to add filters in the qr code reader.
Upvotes: 0
Views: 5162
Reputation: 60691
You have no code to launch the URL. The clue is here:
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
You need to replace the Handle successful scan
reminder with some code to actually handle the scanned URL. For an example of how to launch a URL, see How can I open a URL in Android's web browser from my application?
Upvotes: 1