step:
1.add a plugin created myself to flutter module project
2.run it, and onActivityResult can invoke
3.add flutter module project to android
4.run it, and onActivityResult can't invoke
demo projects:
flutter module with a simple plugin, look at testplugin
android project with flutter module, look at TestPluginAndroid
I found a temporary solution, override onActivityResult in Activity, and do it the following way:
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
mFlutterView.getPluginRegistry().onActivityResult(requestCode, resultCode, data);
}
If you are using FlutterFragment, in Native app, then you may call below method.
flutterFragment.onActivityResult(requestCode, resultCode, data);
hope it helps somebody.
Related
I have just created a react-native library using react-native-create-library and imported it into my master react-native project.
There are some issues I'm having because (honestly) I lack the knowledge.
The problem is that there are no errors (using logcat) and I don't know how I can debug the android part of my imported library.
Example
public class RNZappsCameraModule extends ReactContextBaseJavaModule
implements ActivityEventListener {
#ReactMethod
public void myJavascriptMethod() {
// I want a breakpoint here
// cameraIntent initialization happens here
try
{
currentActivity.startActivityForResult(cameraIntent, requestCode);
}
catch (ActivityNotFoundException e)
{
e.printStackTrace();
}
}
#Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data)
{
// I want a breakpoint here
}
}
The camera intent starts fine, but I believe onActivityResult is never hit.
I know I could log everything and read it, but that won't explain why the result is never returned to my app since there are no errors in the first place.
Google and the official RN documentation are not being my friend at the moment, so please put me on the right track.
Found it.
No rocket science here. I don't know how I managed to do it in the end...
Anyheeew, to give this question a reasonable answer for passers-by...
First off, you need a react-native (master) project in order to actually run your library in a react-native context.
So create it and import your library. The easiest way to do this is by pushing your library into a git repository and adding your library in the package.json of you master project like this:
"react-native-your-package": "git+https://your-git-url-here",
Now install it: npm install react-native-your-package
In order to debug your library:
Open the android project of your react-native project in Android Studio
In menu => view => Tool window, click Build Variants
The new window displays the build types for you project and loaded modules
Click the Build Variant dropdown next to the module you want to debug and select 'debug'
Debug the master Android project
In the projects view, you can expand your module and place breakpoints where ever you like
Click the debug button and fix errors you never head of
I have followed building instructions for tess-two on
Github
I build tess-two using NDK successfully and imported the library
I am trying to run the test application provided on the same repository but whenever the application starts it gives the following exception:
That error is caused once new TessBaseAPI(); is called.
dlopen("/data/app-lib/com.datumdroid.android.ocr.simple-2/liblept.so") failed: Cannot load library: soinfo_link_image(linker.cpp:1635): could not load library "libpng.so" needed by "liblept.so"; caused by load_library(linker.cpp:745): library "libpng.so" not found
Can anyone help with that?
I have followed suggestion of Dmitry Zaitsev & thannks to him , solved my problem also .
Please update your TessBaseAPI.java from tess-two library project as below :
static {
System.loadLibrary("png");
System.loadLibrary("lept");
System.loadLibrary("tess");
nativeClassInit();
}
Build tess-two project after updating these file . In my case I have build it using eclipse.
Hope it should solve your problem as well.
It seems like System.loadLibrary("png") call is missing in TessBaseAPI, therefore library can't be found.
Try to call System.loadLibrary("png") before calling new TessBaseAPI(). Typically this is done in static initialization block, like so:
public class MyClass {
static {
System.loadLibrary("png");
}
public void doStuff() {
new TessBaseAPI();
}
}
Here I am tring to call an activity from a phonegap 3.4 plugin and this is the error being shown in the following code.
public void startActivity() {
Intent myIntent = new Intent(ctx.getContext(), SecActivity.class);
ctx.startActivity(myIntent);
}
"ctx" is showing an error.
But the same code worked with phonegap 1.6.
With what should I replace ctx?
ctx is a legacy member and is deprecated since the release of phonegap 2.0.
Check this link http://docs.phonegap.com/en/2.7.0/guide_plugin-development_android_index.md.html
To rectify the error try replacing ctx.getContext() with this.cordova.getActivity()
This question already has answers here:
Integrating the ZXing library directly into my Android application
(17 answers)
Closed 6 years ago.
I am new to Zxing. I am doing barcode conversion using zxing in my android application. Can anyone guide me how to include zxing to android device.
If the zxing barcode scanner is installed in the mobile, its very easy:
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");//for Qr code, its "QR_CODE_MODE" instead of "PRODUCT_MODE"
intent.putExtra("SAVE_HISTORY", false);//this stops saving ur barcode in barcode scanner app's history
startActivityForResult(intent, 0);
and in OnActivityResult:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = data.getStringExtra("SCAN_RESULT"); //this is the result
} else
if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
If its not installed: u can put this code in try-catch block and catching the exception, u can do this:
Uri marketUri = Uri.parse("market://details?id=com.google.zxing.client.android");
Intent marketIntent = new Intent(Intent.ACTION_VIEW,marketUri);
startActivity(marketIntent);
So it redirects the app to android market and ur app continues running once if the barcode scanner is installed.
If u dont want to use the other app in ur app, U have to download zxing library and try using the classes from core.jar file(it is created using apache ant). Follow this tutorial to do that: https://github.com/zxing/zxing/wiki/Getting-Started-Developing
All Intent options can be found here:
http://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/Intents.java
You need to download the Zing's .Jar file & add in to your application folder. Then you can call classes & methods of it.
Step by step to setup zxing 3.2.1 in eclipse
Download zxing-master.zip from "https://github.com/zxing/zxing"
Unzip zxing-master.zip, Use eclipse to import "android" project in zxing-master
Download core-3.2.1.jar from "http://repo1.maven.org/maven2/com/google/zxing/core/3.2.1/"
Create "libs" folder in "android" project and paste cor-3.2.1.jar into the libs folder
Click on project: choose "properties" -> "Java Compiler" to change level to 1.7. Then click on "Android" change "Project build target" to android 4.4.2+, because using 1.7 requires compiling with Android 4.4
If "CameraConfigurationUtils.java" don't exist in "zxing-master/android/app/src/main/java/com/google/zxing/client/android/camera/". You can copy it from "zxing-master/android-core/src/main/java/com/google/zxing/client/android/camera/" and paste to your project.
Clean and build project. If your project show error about "switch - case", you should change them to "if - else".
Completed. Clean and build project
I am trying to Integrate ZXing QR Code into my android app without installing BarCode Scanner app, I have followed the steps as:
1) Firstly I have downloaded ZXing.zip file and extract it
2)open the ZXing project as an android existing project and then go to android folder and open the android folder and also include core.jar file into the ZXing project named CaptureActivity.
3)I have used the CaptureActivity project as a library in my project named 'QRCodeSample'.
(Problem in including CaptureActivity as a library)
4)My code is as below3:
public class QRCodeSampleActivity extends Activity {
Button b1;
static String contents;
public static final int REQUEST_CODE = 1;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b1 = (Button) findViewById(R.id.button1);
b1.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("com.google.zxing.client.android.SCAN.SCAN_MODE",
"QR_CODE_MODE");
startActivityForResult(intent, 0);*/
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) {
contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
Log.i("Barcode Result", contents);
Intent i1 = new Intent(QRCodeSampleActivity.this, webclass.class);
startActivity(i1);
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
Log.i("Barcode Result","Result canceled");
}
}
}
}
The manifest file is :
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<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>
<activity
android:label="#string/app_name"
android:name=".QRCodeSampleActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".webclass"></activity>
</application>
</manifest>
and its not adding library also
When I am trying to run my project,the error msg is:
Unable to instantiate activity ComponentInfo{com.qr.code/com.qr.code}: java.lang.ClassNotFoundException: com.qr.code in loader dalvik.system.PathClassLoader[/data/app/com.qr.code-1.apk]
Finally I got the answer,
As of ADT 14,the resource fields(such as R.id.decode) are no longer constants when defined in library projects
So in the ZXing library->android->com.google.zxing.client.android.CaptureActivityHandler.java and DecodeHandler.java
Replace both of these classes switch case statements with if-else,and then import this ZXing library into your project..
Rest of the coding of my own project is same...just the problem with the library classes as these are not updated as according to ADT 14..
Kanika
For all those Android Studio/Gradle users out there
Okay guys, as my task today was to integrate ZXING into an Android application and there were no good sources for input all over, I will give you a hint what made my be successful - cause it turned out to be very easy (on version 2.*).
There is a real handy git repository that provides the zxing android library project as an AAR archive.
https://github.com/embarkmobile/zxing-android-minimal
All you have to do is add this to your build.gradle
repositories {
mavenCentral()
maven {
url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/"
}
}
dependencies {
compile 'com.google.zxing:core:2.2'
compile 'com.embarkmobile:zxing-android-minimal:1.2.1#aar'
}
and Gradle does all the magic to compile the code and makes it accessible in your app.
To start the Scanner afterwards, use this class/method:
IntentIntegrator.initiateScan(this); // `this` is the current Activity
If you already visited the link you gonna see that i just copy&pasted the code from there the git readme. If not go there to get some more insight and code examples!
Hope to be helpful for future readers. Peace :)
I had the same Problem and after hours struggling with it I finally managed to solve it like this. as Rubiraj is pointing
*Right Click on your project > Properties > Android > (under tab library) Add the Zxing project *
Assuming you were able to correctly create Zxing project as a Library as it is explained here :
http://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app-natively-using-eclipse/
You need to follow step as given by the link
http://www.androidaz.com/development/zxing-qr-reader-direct-integration
you can download core.jar from
http://repo1.maven.org/maven2/com/google/zxing/core/2.2/
The above is working for me, if your program still just put the core-2.2.jar in libs and clean your project
MaterialBarcodeScanner: Easy to use barcode reader for your Android Project (Uses Google Mobile Vision API).
Provide gradle dependency
compile 'com.edwardvanraak:MaterialBarcodeScanner:0.0.6-ALPHA'
Build a MaterialBarcodeScanner
private void startScan() {
/**
* Build a new MaterialBarcodeScanner
*/
final MaterialBarcodeScanner mBarcodeScanner
= new MaterialBarcodeScannerBuilder()
.withActivity(MainActivity.this)
.withEnableAutoFocus(true)
.withBleepEnabled(true)
.withBackfacingCamera()
.withText("Scanning...")
.withResultListener(new MaterialBarcodeScanner.OnResultListener() {
#Override
public void onResult(Barcode barcode) {
barcodeResult = barcode;
result.setText(barcode.rawValue);
}
})
.build();
mBarcodeScanner.startScan();
}
Hook it up to a button
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startScan();
}
});
Start scanning!
Step by step to setup zxing 3.2.1 in eclipse
Download zxing-master.zip from "https://github.com/zxing/zxing"
Unzip zxing-master.zip, Use eclipse to import "android" project in zxing-master
Download core-3.2.1.jar from "http://repo1.maven.org/maven2/com/google/zxing/core/3.2.1/"
Create "libs" folder in "android" project and paste cor-3.2.1.jar into the libs folder
Click on project: choose "properties" -> "Java Compiler" to change level to 1.7. Then click on "Android" change "Project build target" to android 4.4.2+, because using 1.7 requires compiling with Android 4.4
If "CameraConfigurationUtils.java" don't exist in "zxing-master/android/app/src/main/java/com/google/zxing/client/android/camera/". You can copy it from "zxing-master/android-core/src/main/java/com/google/zxing/client/android/camera/" and paste to your project.
Clean and build project. If your project show error about "switch - case", you should change them to "if - else".
Completed. Clean and build project. You can click on "Proprties" > "Android" > click on "Is Libraries" to use for your project
After importing Zxing as existing project, Properties > Java Buildpath > Check "is library" (check button) and then try to add Zxing as library.
Make sure webclass.class exist in your QRcodesampleActivity.java