J'essaie d'implémenter un lecteur de code QR dans mon application android. J'ai suivi ces étapes:Impossible d'implémenter le lecteur de code QR dans mon application Android
a créé un projet de bibliothèque d'échantillons de la zxing.zip,/android et/core
Ajouté la bibliothèque créée à mon application
Mon code est comme ci-dessous:
public class main extends Activity {
/** Called when the activity is first created. */
Button scanButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
scanButton = (Button) findViewById(R.id.button1);
scanButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// 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
}
}
}
Le scanner ne démarre pas et je reçois cette erreur:
05-08 14:12:03.313: ERROR/AndroidRuntime(718): Caused by: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity in loader dalvik.system.PathClassLoader[/data/app/com.scanner.demo-2.apk]
Le manifeste:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.scanner.demo" android:versionCode="1" android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".main" 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>
Pouvez-vous préciser la question réelle que vous demandez s'il vous plaît? Comment ça échoue? Où échoue-t-il? –
@NeilTownsend Le scanner ne démarre pas et j'obtiens cette erreur: 05-08 14: 12: 03.313: ERROR/AndroidRuntime (718): Causée par: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity loader dalvik.system.PathClassLoader [/data/app/com.scanner.demo-2.apk] –
Si vous êtes, comme l'a souligné @Sean Owen, incorporant du code tiers dans votre application, il est important de (a) (b) assurez-vous de ne pas violer les droits d'auteur sur les paquets. Même si ce que vous essayez de faire est techniquement possible, ce n'est pas la façon de le faire dans ce cas. –