Zbar integration into Android app - android

I am using the Android ADT Bundle for dev work. After reading multiple guides online I have added the package com.dm.zbar.android.scanner to my project. I have included the files CameraPreview.java, ZBarConstants.java, and ZBarScannerActivity.java in the package. Despite all this the ZBAR_SCANNER_REQUEST var in the class ScanActivity.java (created by me, but using zbar methods) cannot be resolved to a variable. Everything except this variable is accepted. Any idea why this is occurring? Note: My libs folder contains everything in here:
https://github.com/DushyanthMaguluru/ZBarScanner/tree/master/ZBarScannerLibrary/libs
and zbar.jar is included on the build path.
ScanActivity:
package com.xx.xxx;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;
import com.dm.zbar.android.scanner.ZBarConstants;
import com.dm.zbar.android.scanner.ZBarScannerActivity;
import net.sourceforge.zbar.Symbol;
public class ScanActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scan);
}
public void launchScanner(View v) {
if (isCameraAvailable()) {
Intent intent = new Intent(this, ZBarScannerActivity.class);
startActivityForResult(intent, ZBAR_SCANNER_REQUEST);
} else {
Toast.makeText(this, "Rear Facing Camera Unavailable", Toast.LENGTH_SHORT).show();
}
}
public void launchQRScanner(View v) {
if (isCameraAvailable()) {
Intent intent = new Intent(this, ZBarScannerActivity.class);
intent.putExtra(ZBarConstants.SCAN_MODES, new int[]{Symbol.QRCODE});
startActivityForResult(intent, ZBAR_SCANNER_REQUEST);
} else {
Toast.makeText(this, "Rear Facing Camera Unavailable", Toast.LENGTH_SHORT).show();
}
}
public boolean isCameraAvailable() {
PackageManager pm = getPackageManager();
return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case ZBAR_SCANNER_REQUEST:
case ZBAR_QR_SCANNER_REQUEST:
if (resultCode == RESULT_OK) {
Toast.makeText(this, "Scan Result = " + data.getStringExtra(ZBarConstants.SCAN_RESULT), Toast.LENGTH_SHORT).show();
}
break;
}
}
}
Just in case it is relevant:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xx.xxx"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<application
android:icon="#drawable/ic_launcher"
android:label="xx"
android:theme="#style/AppTheme" >
<activity android:name="com.xx.xxx.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.xx.xxx.WvActivity" />
<activity android:name="com.xx.xxx.ScanActivity" />
<activity
android:name="com.dm.zbar.android.scanner.ZBarScannerActivity"
android:screenOrientation="landscape" />
</application>

I checked the ZBar Library Example. You made a mistake.
This error occurred because you did not declare these two variables in your activity
private static final int ZBAR_SCANNER_REQUEST = 0;
private static final int ZBAR_QR_SCANNER_REQUEST = 1;
you need to declare these variables above your onCreate(..) Method.
See the ZBar Example.

Related

My Bluetooth application crashes for a some reason

My mainactivity
package com.example.vivek.trackblue;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
Context context = getApplicationContext();
CharSequence text = "Bluetooth is not supported";
int duration = Toast.LENGTH_SHORT;
Toast toast1 = Toast.makeText(context, text, duration);
Button b1 = (Button)findViewById(R.id.button);
private final static int REQUEST_ENABLE_BT=1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
if(bt == null){
toast1.show();
}
if(bt.isEnabled())
{
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
}
});
}
}
and this is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.vivek.trackblue">
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<permission android:name="android.permission.BLUETOOTH" android:label="BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I am Trying to create an application where the user would press a button to start Bluetooth.
My code shows no errors on the ide but when it gets installed in the device, it crashes with an error "Unfortunately TrackBlue stopped working". Here trackblue is my application's name.
Simply because you have assigned value to button variable before setting content view for the screen.
Error is because it tries to find the view by the given button's ID even before it is set on to screen.
Solution:
Write the findViewById() line after setContentView() inside onCreate()

Same xml code, different graphic layout

I am new to android development and i tried copying an xml layout from another project, but the graphic layout of that xml seems to be different from what i am getting. I have no idea what is missing in my project that I am not getting the same layout. Please help.
this is what it looks like
!1
and this is what i get after copying the exact code.
!2
my xml file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aditya.contentsharer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name=".InteriorSpottingApplication"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".InteriorListActivity"
android:label="#string/title_activity_interior_list" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="android.app.Activity" />
</activity>
<activity
android:name=".NewInteriorActivity"
android:label="#string/title_activity_new_interior" >
</activity>
</application>
</manifest>
xml code
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
java code
package com.aditya.contentsharer;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.parse.ParseQueryAdapter;
public class InteriorListActivity extends ListActivity{
private ParseQueryAdapter<Interior> mainAdapter;
private FavoriteInteriorAdapter favoritesAdapter;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getListView().setClickable(false);
mainAdapter = new ParseQueryAdapter<Interior>(this, Interior.class);
mainAdapter.setTextKey("title");
mainAdapter.setImageKey("photo");
// Subclass of ParseQueryAdapter
favoritesAdapter = new FavoriteInteriorAdapter(this);
// Default view is all interiors
setListAdapter(mainAdapter);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_interior_list, menu);
return true;
}
/*
* Posting interiors and refreshing the list will be controlled from the Action
* Bar.
*/
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_refresh: {
updateinteriorList();
break;
}
case R.id.action_favorites: {
showFavorites();
break;
}
case R.id.action_new: {
newinterior();
break;
}
}
return super.onOptionsItemSelected(item);
}
private void updateinteriorList() {
mainAdapter.loadObjects();
setListAdapter(mainAdapter);
}
private void showFavorites() {
favoritesAdapter.loadObjects();
setListAdapter(favoritesAdapter);
}
private void newinterior() {
Intent i = new Intent(this, NewInteriorActivity.class);
startActivityForResult(i, 0);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
// If a new post has been added, update
// the list of posts
updateinteriorList();
}
}
}
I got the solution. I removed android:theme="#style/AppTheme" from the manifest file. That worked fine for me.
I am not used to deal with ListActivities since I usually do it with a ListView in a normal activity but my first guess is that you still need to have a line like this in your onCreate() method to actually get any layout...
setContentView(R.layout.fragmentContainer);
(assuming your xml file has the same name as it's ID right?
Try putting it after the
super.onCreate(savedInstanceState);
I am not sure if it will work but try it! :)

how to mopub ads add in application

i want to add ads banner in my application i have integrate mopub sdk with my project and import and add library to the my project now my question is how to add banner disply and where code i have to write in my application java code and xml code about ads so please help enyone
my java code and mainifest file code is given below
mainactivity.java
package com.example.ration;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class MainActivity extends Activity {
private WebView web;
int k;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
web=(WebView)findViewById(R.id.web);
web.getSettings().setJavaScriptEnabled(true);
web.setWebViewClient(new WebViewClient());
web.getSettings().setBuiltInZoomControls(true);
web.loadUrl("http://dcs-dof.gujarat.gov.in/live-info.htm");
// web.getProgress();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0,1,menu.NONE,"About");
menu.add(0,2,menu.NONE,"Feedback");
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id=item.getItemId();
if(id == 1)
{
Toast.makeText(MainActivity.this,"About",Toast.LENGTH_LONG).show();
Intent i=new Intent(MainActivity.this,about.class);
startActivity(i);
}
else {
Toast.makeText(MainActivity.this,"Feedback",Toast.LENGTH_LONG).show();
Intent i2 =new Intent(MainActivity.this,feedback.class);
startActivity(i2);
}
return super.onOptionsItemSelected(item);
}
private boolean doubleBackToExitPressedOnce = false;
#Override
protected void onResume() {
super.onResume();
// .... other stuff in my onResume ....
this.doubleBackToExitPressedOnce = false;
}
#Override
public void onBackPressed() {
if (doubleBackToExitPressedOnce) {
super.onBackPressed();
return;
}
this.doubleBackToExitPressedOnce = true;
Toast.makeText(this,"Press Again to Exit", Toast.LENGTH_SHORT).show();
}
}
and my manifest file is
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ration"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.ration.MainActivity"
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.example.ration.about"></activity>
<activity android:name="com.example.ration.feedback"></activity>
<activity android:name="com.mopub.mobileads.MoPubActivity" android:configChanges="keyboardHidden|orientation"/>
<activity android:name="com.mopub.mobileads.MraidActivity" android:configChanges="keyboardHidden|orientation"/>
<activity android:name="com.mopub.mobileads.MraidBrowser" android:configChanges="keyboardHidden|orientation"/>
<activity android:name="com.mopub.mobileads.MraidVideoPlayerActivity" android:configChanges="keyboardHidden|orientation"/>
<activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<activity android:name="com.millennialmedia.android.MMActivity" android:theme="#android:style/Theme.Translucent.NoTitleBar" android:configChanges="keyboardHidden|orientation|keyboard" />
<activity android:name="com.millennialmedia.android.VideoPlayer" android:configChanges="keyboardHidden|orientation|keyboard" />
</application>
</manifest>
I think you should better go through the guide for Mopub Banner Ads Integration which explains you the steps of banner ads integration.
Hope this will help you.
Use view in XML file
<com.mopub.mobileads.MoPubView
android:id="#+id/mrect_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
in activity Load code
pass id of view in below function ,unit id of ur app,and keywords of cataogry of ads
public void loadMoPubView(MoPubView moPubView, String adUnitId, String keywords) {
if (moPubView == null) {
Utils.logToast(LockScreenActivity.this, "Unable to inflate MoPubView from xml.");
//Toast.makeText(this, "Unable to inflate MoPubView from xml.", Toast.LENGTH_SHORT).show();
return;
}
try {
Utils.validateAdUnitId(adUnitId);
} catch (IllegalArgumentException exception) {
Utils.logToast(LockScreenActivity.this, exception.getMessage());
return;
}
moPubView.setBannerAdListener(this);
moPubView.setAdUnitId(adUnitId);
moPubView.setKeywords(keywords);
moPubView.setAutorefreshEnabled(true);
moPubView.loadAd();
}

How to initialize the parse.com code in Android

I am trying to use the Parse.com sdk and I can't get my Parse codes to initialize. I don't know where to put it and I need help because I can't tell if I need to put it in my main or if I need to put it in somewhere else.
This is a few blocks of code I have put in different classes
I created this with the sample
package com.example.musicdroid;
import com.parse.Parse;
import com.parse.ParseACL;
import com.parse.ParseUser;
import android.app.Application;
public class ParseApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
// Add your initialization code here
Parse.initialize(this, "XXX", "XXX");
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
ParseACL.setDefaultACL(defaultACL, true);
}
}
This is where I had it originally
import com.parse.Parse;
import com.parse.ParseAnalytics;
import com.parse.ParseInstallation;
import com.parse.PushService;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Main extends ListActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] choices = { "Rock", "Metal", "Rap", "My Favorites" };
setListAdapter(new ArrayAdapter<String>(this, R.layout.main,
R.id.music, choices));
}
protected void onListItemClick(ListView l, View v, int position, long id) {
switch (position) {
case 0:
try {
startActivity(new Intent(
Intent.ACTION_VIEW,
Uri.parse("spotify:user:warnermusicus:playlist:3DRD3GUpQSjK2rryIRVOPS")));
} catch (ActivityNotFoundException e) {
final Intent intent = new Intent(
Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=com.spotify.mobile.android.ui"));
startActivity(intent);
}
break;
case 1:
try {
startActivity(new Intent(
Intent.ACTION_VIEW,
Uri.parse("spotify:user:warnermusicus:playlist:6iIDHF5tBqzS6uZjMEzBdQ")));
} catch (ActivityNotFoundException e) {
final Intent intent = new Intent(
Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=com.spotify.mobile.android.ui"));
startActivity(intent);
}
break;
case 2:
try {
startActivity(new Intent(
Intent.ACTION_VIEW,
Uri.parse("spotify:user:digsterdeutschland:playlist:5pvJLjAhcKCHXGOb7pEbBZ")));
} catch (ActivityNotFoundException e) {
final Intent intent = new Intent(
Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=com.spotify.mobile.android.ui"));
startActivity(intent);
}
break;
case 3:
try {
startActivity(new Intent(
Intent.ACTION_VIEW,
Uri.parse("spotify:user:digsterdeutschland:playlist:1hYWCuFv5Eav9yIZXHwnpd")));
} catch (ActivityNotFoundException e) {
final Intent intent = new Intent(
Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=com.spotify.mobile.android.ui"));
startActivity(intent);
}
break;
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Another place I had it. This is the Main Menu
package com.example.musicdroid;
import com.parse.Parse;
import com.parse.ParseAnalytics;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainMenu extends ListActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] choices = { "Main", "Bios", "Artist Search", "How To Use" };
setListAdapter(new ArrayAdapter<String>(this, R.layout.menu, R.id.Menu,
choices));
}
protected void onListItemClick(ListView l, View v, int position, long id) {
switch (position) {
case 0:
startActivity(new Intent(MainMenu.this, Main.class));
break;
case 1:
startActivity(new Intent(MainMenu.this, Bios.class));
break;
case 2:
startActivity(new Intent(MainMenu.this, Search.class));
break;
case 3:
startActivity(new Intent(MainMenu.this, How.class));
break;
}
}
}
Manifest Code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.musicdroid"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="com.example.musicdroid.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.musicdroid.permission.C2D_MESSAGE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/fiery_music_symbol"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo" >
<activity
android:name="com.example.musicdroid.Main"
android:label="#string/app_name" >
</activity>
<activity android:name=".MainMenu" >
</activity>
<activity android:name=".Bios" >
</activity>
<activity android:name=".Search" >
</activity>
<activity android:name=".How" >
</activity>
<activity android:name=".LoginSignupActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Welcome" >
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver
android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.example.musicdroid" />
</intent-filter>
</receiver>
</application>
</manifest>
Add Your class extending Application inside Manifest File
<application android:name="your packagename.ParseApplication"
android:icon="#drawable/icon"
android:label="#string/app_name">
I hope this helps..
Just put it to your MainActivity.java to onCreate with all the statements, which you have in ParseApplication's class onCreate. Then you can remove this class (ParseApplication.java)
It should work properly.
Hope it helps
You should always place the initialize call in the ACTIVITY's onCreate method, just after the setContentView call. Like this:
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_name_here);
Parse.initialize(this, "ApplicationKey", "ClientKey);
// Rest of your code follows...
}
Once you have that line, you can then do any Parse transactions.
Say you can't have custom app class (Eg: Android Library)
You can use the following procedure
Call initialize like this:
if (ParseCheck.isParseInitialized())
Parse.initialize(context, PARSE.AB4FUN_APP.APPLICATION_ID, PARSE.AB4FUN_APP.CLIENT_KEY);
Create a utility class like below (note the package)
package com.parse;
public class ParseCheck {
public static boolean isParseInitialized(){
return Parse.isInitialized();
}
}
import android.app.Application;
import com.parse.Parse;
public class MyApp extends Application {
#Override public void onCreate() {
super.onCreate();
Parse.initialize(this, ApplicationID, ClientKey);
}
}
Then, add the following to your <application> in AndroidManifest.xml:
name=".MyApp"

Android Barcode Scanner

I am using Biggu barcode library.
Packaged library has been listed everything using demo and sample application.
But I am getting no class definition found error
java.lang.NoClassDefFoundError: com.biggu.scannerdemo.ScannerActivity
But the class is in package and manifest file lists all the activities.
Build path has biggu_scanner-1.1.0.jar file in its path.
package com.biggu.scannerdemo;
import com.biggu.barcodescanner.client.android.Intents;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class Demo extends Activity {
private static final int SCANNER_REQUEST_CODE = 0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button)findViewById(R.id.btn);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), com.biggu.scannerdemo.ScannerActivity.class);
intent.putExtra(Intents.Preferences.ENABLE_BEEP, true);
intent.putExtra(Intents.Preferences.ENABLE_VIBRATE, true);
((Activity)v.getContext()).startActivityForResult(intent, SCANNER_REQUEST_CODE);
}
});
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK && requestCode == SCANNER_REQUEST_CODE) {
Bundle extras = data.getExtras();
String result = extras.getString("SCAN_RESULT");
TextView textView = (TextView)findViewById(R.id.txt);
textView.setText(result);
}
}}
ScannerActivity is having the below code
package com.biggu.scannerdemo;
import com.biggu.barcodescanner.client.android.CaptureActivity;
public class ScannerActivity extends CaptureActivity {
#Override
public int get_R_id_preview_view() {
return R.id.preview_view;
}
#Override
public int get_R_id_viewfinder_view() {
return R.id.viewfinder_view;
}
#Override
public int get_R_layout_scanner() {
return R.layout.scanner;
}
#Override
public int get_R_raw_beep() {
return R.raw.beep;
}
}
Android manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.biggu.scannerdemo"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".Demo"
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=".ScannerActivity"
android:label="Scanner Activity" android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden" android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
</activity>
</application>
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
Tried everything to set right
Could anyone let me know what could be the wrong in the code.
Looking forward to your reply.thanks.
You must make sure that your lib is exported when building the APK.
In Project properties > Java Build Path > Order and Export => check your lib
You need to add the library in the project preferences.

Categories

Resources