Gluon Charm Down Barcode Scanner - Intent handler not found - android

I am using Netbeans 8.1 and the gluonhq jfxplugin 2.2.0.
I am trying to read a barcode, and created a new project (the standard hello world). I changed the button handler to call a function UpdateText() (below) which in turn calls the Charm Down Scan service.
When I run the app, and click on the button I get the following error in the Android Device Manager:
E/AndroidRuntime(3583): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.gluonhq.charm.down.android.scan.SCAN cat=[android.intent.category.DEFAULT] flg=0x4080000 }
This crash is happening on the scanservice.scan() line.
Button click handler code:
protected void UpdateText(Label label) {
ScanService scanService = PlatformFactory.getPlatform().getScanService();
StringProperty scannedString = scanService.scan();
scannedString.addListener((obs, ov, nv) -> System.out.println("Scanned String = " + nv));
}
I would greatly appreciate any help

You need to define the com.gluonhq.charm.down.android.scan.SCAN intent in your AndroidManifest.xml file. Add the following activity definition below your main activity definition:
<activity android:name="com.gluonhq.charm.down.android.scan.zxing.CaptureActivity"
android:screenOrientation="sensorLandscape"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="com.gluonhq.charm.down.android.scan.SCAN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
By default, the AndroidManifest.xml file is generated for you under the hood by the plugin. If you haven't setup a custom AndroidManifest.xml file yet, you can copy the one that the plugin generates. The default version is located in build/javafxports/tmp/android/AndroidManifest.xml. Just copy that one to a persistent location, i.e. src/android. Then update your build.gradle to tell the plugin that it should use the custom AndroidManifest.xml file instead of generating the default one:
jfxmobile {
android {
manifest = 'src/android/AndroidManifest.xml'
}
}
update:
You also need to add an extra dependency to the zxing core library as it seems it isn't included automatically when depending on the charm library alone:
dependencies {
androidRuntime 'com.google.zxing:core:3.2.1'
}
Furthermore, you'll have to add the CAMERA permission to your manifest as well:
<uses-permission android:name="android.permission.CAMERA"/>

Related

add attribute to capacitor-cordova-android-plugins ShareChooserPendingIntent receiver

In attempt to update the targetSdkVersion to 31 I have encountered this merge manifest error:
Error: android:exported needs to be explicitly specified for . Apps targeting Android 12 and higher are required to specify an explicit value for android:exported when the corresponding component has an intent filter defined.
The file causing this issue is capacitor-cordova-android-plugins/src/main/AndroidManifest.xml at application/receiver "nl.xservices.plugins.ShareChooserPendingIntent".
<receiver android:name="nl.xservices.plugins.ShareChooserPendingIntent" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
</intent-filter>
</receiver>
Build works fine when I manually add the attribute android:exported="false" to the receiver but the problem is that this file is regenerated upon sync/build.
How can I add this attribute without manually editing the file?
I had to use Capacitor CLI Hooks to rewrite the file as seen here.
package.json:
"scripts": {
...
"capacitor:update:after": "cd scripts/capacitor-cordova-android-plugins && CapacitorCordovaAndroidPlugins",
"capacitor:sync:after": "cd scripts/capacitor-cordova-android-plugins && CapacitorCordovaAndroidPlugins"
}
CapacitorCordovaAndroidPlugins.cs:
where src is you path to the manifest file (stackoverflow was having trouble posting with that string???)
using System;
using System.IO;
using System.Text.RegularExpressions;
namespace CapacitorCordovaAndroidPlugins {
public class App {
[STAThread]
static void Main() {
string src = "";
string content = File.ReadAllText(src);
string pattern = #"(<receiver .*(?<!android:exported=""false""))(?=>)";
string replacement = #"$1 android:exported=""false""";
content = Regex.Replace(content, pattern, replacement);
File.WriteAllText(src, content);
}
}
}

Android Studio unable to find explicit activity class Library After Merge Manifest

I Have Application where use library Pick Image. But When I use it like this :
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new TedPermission(getApplicationContext())
.setPermissionListener(permissionGetFotoListener)
.setDeniedMessage("If you reject permission,you can not use this service\n" +
"Please turn on permissions at [Setting] > [Permission]")
.setPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE)
.check();
}
i got error :
android.content.ActivityNotFoundException: Unable to find explicit
activity class
{com.myapp.android/com.gun0912.tedpermission.TedPermissionActivity};
have you declared this activity in your AndroidManifest.xml
update
I used any Library.
This problem occurs when the added tools: node = "replace" on the manifest, but if it is removed, I get an error manifest merge failed
so how to fix it ?
add the activity to androidManifest.xml
or maybe the image pick library required their own activity to the manifest
<Application
.....>
<activity
android:name=".TedPermissionActivity"/>
</application>

Facebook Sdk Has Not Been Initialized FacebookSdk.sdkInitialize()

Hey I know this was asked before, but none of the solutions seem to help. I'm using first time Facebook SDK in my application.
What I've tried:
I had tried most of the things found on Internet but did not get anything regarding this.
Here is my MainActivity.java:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FacebookSdk.sdkInitialize(getApplicationContext());
}
}
Here is My Activitymain.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:facebook="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.facebook.login.widget.LoginButton
android:id="#+id/connectWithFbButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal"
android:text=" connect_with_facebook" />
</LinearLayout>
see my Logcat:
05-13 16:30:39.332: E/AndroidRuntime(10264): Caused by: The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.
Problem
While integrating Android SDK for a react-native project, I had finished the Android with React Native v0.30+ Project Configuration guide, and ran react-native run-android and then got this screen:
I learned that FacebookSdk.sdkInitialize is deprecated. see here
After some searching, I realized that the guide did not contain the steps to add the Facebook App ID for my app.
Solution
Open android/app/src/main/AndroidManifest.xml file and look in the <application> tag to confirm that this meta-data tag exists:
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id"/>
Open android/app/src/main/res/values/strings.xml file and confirm that this there is a "facebook_app_id" string tag with your app id as the value:
<string name="facebook_app_id">YOUR_APP_ID_HERE</string>
Run react-native run-android.
These are the steps that worked for me.
You have to use FacebookSdk.sdkInitialize(getApplicationContext()); before setContentView(R.layout.activity_main); as documentation states out. In case you need a complete facebook login example, check this one here.
You don't need to use FacebookSdk.sdkInitialize anymore. Check if your:
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id"/>
is inside <application> tag.
For SDK v13.+ you must add Apple ID and Client Token.
Open the /app/res/values/strings.xml file in your app project and add:
<string name="facebook_app_id">1234</string>
<string name="facebook_client_token">56789</string>
Open the /app/manifests/AndroidManifest.xml file in your app project and add:
<application android:label="#string/app_name" ...>
...
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
<meta-data android:name="com.facebook.sdk.ClientToken" android:value="#string/facebook_client_token"/>
...
</application>
You can find your Client Token in your FB Developer account:
App > Dashboard > Settings > Advanced > Security > Client token.
There is a reason why sdkInitialize() is deprecated.
Go to your manifest file within the android folder and add following
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id"/>
After that append in your strings.xml file (res/values/strings.xml) the string entry:
<string name="facebook_app_id">APP_ID</string>
Close your Metro Builder and rebuild your Project using react-native run-android
Follow only 2 Step and your Facebook Sdk iw working in React Native
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id"/>
<string name="facebook_app_id">YOUR_APP_ID_HERE</string>
Don't Need this b'coz Its Deprecated Now
FacebookSdk.sdkInitialize(getApplicationContext());
After checking the documentation I found that they are asking to initialize FacebookSdk in Application class onCreate() Method.
Snap code from Facebook doc:
public class MyApplication extends Application {
// Updated your class body:
#Override
public void onCreate() {
super.onCreate();
// Initialize the SDK before executing any other operations,
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
}
}
Seeing the responses listed in this question, the old way to initialize Facebook was:
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
// Initialize the SDK before executing any other operations,
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
}
}
But we can get the message:
Facebook Sdk Has Not Been Initialized FacebookSdk.sdkInitialize()
FacebookSdk.sdkInitialize() now is deprecated.
Now (2021) Facebook initialization has changed, the Facebook initialization is automatically.
1 Add the following to the dependencies {} section of your build.gradle (module: app) file to compile the latest version of the Facebook SDK for Android:
implementation 'com.facebook.android:facebook-android-sdk:latest.release'
Add Your Facebook App ID and Client Token
Add your Facebook App ID and Client Token to your project's strings file and update your Android manifest:
1 Open your /app/res/values/strings.xml file.
2 Add a string element with the name attribute facebook_app_id and value as your Facebook App ID to the file. For example
<string name="facebook_app_id">Facebook App ID</string>
<string name="facebook_client_token">Facebook Client ID</string>
3 Open /app/manifests/AndroidManifest.xml
4 Add a uses-permission element to the manifest:
<uses-permission android:name="android.permission.INTERNET"/>
5 Add a meta-data element to the application element:
<application android:label="#string/app_name" ...>
...
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
<meta-data android:name="com.facebook.sdk.ClientToken" android:value="#string/facebook_client_token"/>
...
</application>
Use Initialise Callback Constructor like this:
Handler mHandler = new Handler();
FacebookSdk.InitializeCallback initializeCallback = new FacebookSdk.InitializeCallback() {
#Override
public void onInitialized() {
mHandler.post(new Runnable() {
#Override
public void run() {
//UI Code Here
}
});
}
};
//before setContentView()
FacebookSdk.sdkInitialize(getActivity().getApplicationContext(),initializeCallback);
If this helps anyone. For me I had to make this change
implementation 'com.facebook.android:facebook-login:latest.release' // for FB login
the above line of code must be added to the END of the dependencies object and not anywhere in between.
This is in android/app/build.gradle file
My app was crashing because the Privacy Policy url was not provided in "Settings/Basic" in https://developers.facebook.com/. (in fact it was provided but I had to "Save changes" again. Seems a bug from Facebook).
The app was working fine and the error message Facebook Sdk Has Not Been Initialized FacebookSdk.sdkInitialize()disappeared. Hope this help.
For me, this issue arose due to a package in my application called react-native-fbsdk.
Please check your package.json file for the same.
I removed the package using npm uninstall fbsdk and rebuilt by app and it worked perfectly.
Hope this solution works for you!
remove android:exported=true from AndroidManifest.xml and targetSdkVersion should be less than 31

Android Gradle Build Variant Deploy

I just finished setting up build variants with Gradle in Android Studio. What a blessing this will be for a typical demo/pro setup. I'm able to launch my 'demoDebug' app perfectly fine. When I switch to 'proDebug' and 'Run" with the same configuration it installs the pro app fine but crashes launching it:
Starting: Intent { act=android.intent.action.MAIN
cat=[android.intent.category.LAUNCHER]
cmp=com.anthonymandra.rawdroidpro/com.anthonymandra.rawdroid.RawDroid
} Error type 3 Error: Activity class
{com.anthonymandra.rawdroidpro/com.anthonymandra.rawdroid.RawDroid}
does not exist.
If I then go to the dashboard I can launch the pro version and it works as expected. So the install works for the appropriate version; there's only something wrong in the launch (on pro).
build.gradle flavors:
productFlavors {
demo {
packageName "com.anthonymandra.rawdroid"
}
pro {
packageName "com.anthonymandra.rawdroidpro"
}
proAmazon {
packageName "com.anthonymandra.rawdroidpro"
}
}
Update
cleaned up extraneous info unrelated to the issue
When I decompiled the apk I confirmed that none of the gradle overrides were being implemented in the Android.manifest.
First you should have packagename in manner like (recommended approach not mandatory ):
youractualapplicationpackage.flavorname
But you can have packagname whatever you want for flavours like in your case:
productFlavors {
demo {
packageName "com.anthonymandra.rawdroiddemo"
}
pro {
packageName "com.anthonymandra.rawdroidpro"
}
proAmazon {
packageName "com.anthonymandra.rawdroidpro"
}
}
make sure com.anthonymandra.rawdroid is the application's java package inside your main/java directory.
Your AndroidManifest.xml should be like this(Only inside main directory):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.anthonymandra.rawdroid" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".RawDroid"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="#string/app_name"
android:theme="#style/GalleryTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And it should be only in the main directory not anywhere else.
At compilation time gradle will do the necessary package name changes and will make the build.
Same worked fine in my machine and I was able to see two different apps in my device for two different flavors.
The issue was:
'manifestmerger.enabled=false'.
I disabled the function a while back because it caused issues with a library. In the meantime I forgot about it, but apparently the library merging also applies to the gradle merging. I suppose that makes some sense but they really need to allow for separation between gradle merging and library merging.
Thanks to #pyus13 for nonstop support till I came to the typical "Oh s---, are you kidding me..."

Integrate ZXing QR code scanner without installing BarCode Scanner

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

Categories

Resources