I can't connect my Android App with neo4j database - android

I'm programming an app in Android but I canĀ“t connect it to a local neo4j database.
In the gradle I've put this dependencies:
compile 'org.neo4j.driver:neo4j-java-driver:1.4.1'
compile 'org.neo4j:neo4j-jdbc:3.1.0'
The connection code is the following:
import org.neo4j.driver.v1.Driver;
import org.neo4j.driver.v1.GraphDatabase;
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.StatementResult;
import static org.neo4j.driver.v1.Values.parameters;
public class ConsultasBD {
#TargetApi(Build.VERSION_CODES.KITKAT)
public static boolean consultaLogin(String u, String p) {
try {
// Connect
Driver driver = GraphDatabase.driver( "bolt://192.168.0.39:7474");
Session session = driver.session();
// Querying
StatementResult result = session.run( "MATCH (a:Person {usr: {name}, Pass: {pass}})",
parameters( u, p ) );
while ( result.hasNext() )
{
System.out.println("OK");
}
session.close();
driver.close();
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
return true;
}
}
But when I run it, I get this exception:
java.lang.NoClassDefFoundError:
Failed resolution of: Ljava/net/StandardSocketOptions;
And I don't know how can I fix it.
Can anyone explain me how can I connect my app with neo4j?
Thank you very much.
Miguel

StandardSocketOptions was only added to Android in API level 24 (Nougat). So, unless you have a device with API level 24 or higher, you will get that exception.
However, even if you do run your app on such a device, there may be other needed classes that are missing. This is because the neo4j Java libraries do not attempt to target the Android environment (which only supports part of the standard Java libraries). So, this kind of problem is to be expected. Android apps should use the neo4j HTTP API instead.

Related

Got error 403 (Forbidden) when importRoute using Here Android SDK

I'm trying to import a list of Location to calculate the route (using Here Android SDK). However I always got error: (403) Forbidden.
Here SDK's guide: https://developer.here.com/documentation/android-sdk-explore/4.10.5.0/dev_guide/topics/routing.html#import-routes-from-other-services
I've checked key, key_secret and appID for my project, every things is fine.
Here is my code:
val routingEngine = RoutingEngine()
routingEngine.importRoute(
generateGeoLists(),
CarOptions()
) { routingError, routes ->
if (routingError == null) {
routes?.getOrNull(0)?.let {
showRouteOnMap(it)
}
} else {
DebugLog.d("Error import", "import failed: $routingError")
}
}
Please help me to solve this.
Note: Other methods like 'calculateRoute',... work fine except 'importRoute'.
I'm using Here SDK Explore edition.

Android things: DP 7 retired PeripheralManagerService and I have issue with PeripheralManager

I have 1 project based on this: https://github.com/Nilhcem/i2cfun-androidthings
https://github.com/neuberfran/SmartDrive5 (the latter is my project)
But, when I change PeripheralManagerService to PeripheralManager (DP 7 and APi level 27)
try {
PeripheralManager manager = PeripheralManager.getInstance();
mDevice = manager.openI2cDevice(I2C_DEVICE_NAME, I2C_ADDRESS);
} catch (IOException e) {
Log.w(TAG, "Unable to access I2C device", e);
}
I have this issue: https://drive.google.com/file/d/1kXfknYcu4RUF7AT1549_sjJiVSG2_Jjo/view?usp=sharing in this line: https://drive.google.com/file/d/1nTXOV0qiQDe5XldzIuLsY26oIdyfs3x3/view?usp=sharing
I know about this: PeripheralManagerService throws NoClassDefFoundError
but not solved.
Can you help me
The class not found exception means that peripheral manager is not on the operating system. You are trying to use a new API on a device that has an older version.
You need to have the Android things library dependency in sync with the version installed on your device.
And as it has been suggested, you should get everything into the stable release.

Getting Let's encrypt cerificate to work with android api < 20

I have a node server which uses Let's Encrypt CA and it's hosted on zeit.now.
The client is developed using react-native.
I try to connect to it using websockets.
On iOS and newer Android versions (API > 20) it connects successfully.
When running on older Android versions (both on simulator and actual devices) it never connects.
I have tried to connect using older Android version to a server that's not using Let's encrypt CA (but IS using ssl from other provider - hosted on heroku), and it also connects successfully.
So I believe there is something wrong with older Android versions and Let's encrypt certificate.
Could someone help? I have lost 5 days researching this problem and I don't know a lot about JAVA.
EDIT:
I try to connect using websocket
ws.onerror = (e) => {
// an error occurred
console.log(e.message);
};
this logs:
Connection closed by peer
and this method:
ws.onclose = (e) => {
// connection closed
console.log(e.code, e.reason);
};
logs:
undefined, undefined
I fixed it! See this comment.
Basically I needed to install the latest security fixes that are bundled with Google Play Services
I fixed this by adding the following dependency to Gradle:
implementation 'com.google.android.gms:play-services-safetynet:17.0.0'
and then calling
public void onCreate() {
super.onCreate();
try {
ProviderInstaller.installIfNeeded(this);
} catch (GooglePlayServicesRepairableException e) {
// Don't forget exception handling!
} catch (GooglePlayServicesNotAvailableException e) {
// Do something clever
}
SoLoader.init(this, /* native exopackage */ false);
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
}

Use SQLiteNetextensions with Xamarin for Android-App

I've read some threads about SQLite for Xamarin but I'm still not able to set up SQLiteNetExtensions in a proper way. I'm currently developing an android app with Target Framework Android 7.1(API Level 25 - Nougat).
Can anybody tell me what I'm doing wrong?
I installed nuget packages:
Install-Package SQLiteNetExtensions -Version 2.0.0-alpha2 -Pre
Install-Package SQLite.Net-PCL -Version 3.1.1
According to: https://bitbucket.org/twincoders/sqlite-net-extensions
Then I set up my code.
using SQLite.Net.Attributes;
using SQLiteNetExtensions.Attributes;
using System;
namespace AppName.Resources.Model
{
public class Entry
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[ForeignKey(typeof(Stock))]
public int StockId { get; set; }
public DateTime Date { get; set; }
public double Amount { get; set; }
}
}
using SQLite.Net.Attributes;
using SQLiteNetExtensions.Attributes;
using System;
using System.Collections.Generic;
namespace AppName.Resources.Model
{
public class Stock
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
public DateTime LastUpdated { get; set; }
[OneToMany(CascadeOperations = CascadeOperation.All)]
public List<Entry> Entrys { get; set; }
}
}
using Android.Util;
using AppName.Resources.Model;
using SQLite.Net;
using SQLite.Net.Platform.XamarinAndroid;
using SQLiteNetExtensions.Extensions;
using System.Collections.Generic;
using System.IO;
namespace AppName.Resources.DataHelper
{
public class DataBase
{
string folder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
public bool CreateDataBase()
{
try
{
using (var stocksDBConnection = new SQLiteConnection(new SQLitePlatformAndroid(), Path.Combine(folder, "Stock.db")))
{
stocksDBConnection.CreateTable<Entry>();
stocksDBConnection.CreateTable<Stock>();
return true;
}
}
catch (SQLiteException ex)
{
Log.Info("SQLiteEx", ex.Message);
return false;
}
}
public bool InsertIntoTableStock(object stock)
{
try
{
using (var stocksDBConnection = new SQLiteConnection(new SQLitePlatformAndroid(), Path.Combine(folder, "Stock.db")))
{
stocksDBConnection.InsertWithChildren(stock);
return true;
}
}
catch (SQLiteException ex)
{
Log.Info("SQLiteEx", ex.Message);
return false;
}
}
...
These References were added by nuget:
SQLite-net
SQLite.Net
SQLite.Net.Platform.XamarinAndroid
SQLiteNetExtensions
SQLitePCLRaw.Batteries_green
SQLitePCLRaw.Core
SQLitePCLRaw.lib.e_sqlite3
SQLitePCLRaw.provider.e_sqlite3
Occuring error:
'SQLiteConnection' does not contain a definition for 'InsertWithChildren' and the best extension method overload 'WriteOperations.InsertWithChildren(SQLiteConnection, object, bool)' requires a receiver of type 'SQLiteConnection'
'SQLiteConnection' does not contain a definition for 'GetAllWithChildren' and the best extension method overload 'ReadOperations.GetAllWithChildren(SQLiteConnection, Expression>, bool)' requires a receiver of type 'SQLiteConnection'
Well that's how far I get. Anybody out there who knows what to do? Maybe remove conflicting references?
Ok I'm sure that its just a version problem because I just tried your code and it works fine for me. Try installing SQliteNetExtensions v 1.3.0 package from the NuGet package manager window in Visual Studio and nothing else. It will install all its dependencies.
Here is what I did - Try to do the same and see if this helps :
I Created a new Android Single View App Project in Visual Studio
(I'm using community 2017 - but it should not matter ) and created
the Stock , Entry and Database Classes and pasted your given
code respectively.
I installed only the SQliteNetExtensions v 1.3.0 package from the NuGet Package Manager
It installed the following dependencies along with it, I didn't installed these myself.
SQLite.Net-PCL v3.0.5
NewtonSoft.Json v6.0.8
Here is what I got after installing just SQliteNetExtensions v 1.3.0 package.
As you can see its showing an update for SQLite.Net-PCL v3.0.5 to v3.1.1 I tired also with the updated one and it still works fine , so its up to you to update or not.
Here a bit proof that its working fine. I also compiled and run the app on emulator and it works all fine.
Ok after a bit of searching , I came to know that the creator of this extension used a pattern called MvvmCross while developing it. So unless you are using that pattern model you will get this error.
For non-MvvmCross users they have to rebuild the source files and reference it in their project and not use the pre-compiled one, the one you are using.
Go to the fourth post on the following link
https://forums.xamarin.com/discussion/20117/sqlite-net-extensions-and-sqliteconnection here he tells how to rebuild from source in his post in a very brief manner.
Hope you will understand it but if not wait till I install Visual Studio and Xamarin and try it out myself so I can give you accurate steps.
It will take a while so till then , Kudos!
Here is the link to source files https://bitbucket.org/twincoders/sqlite-net-extensions/downloads/
Click on download repository
After some research I found out that:
Install-Package SQLiteNetExtensions -Version 2.0.0-alpha2 -Pre
depends on
Install-Package sqlite-net-pcl
instead of
Install-Package SQLite.Net-PCL -Version 3.1.1
But after removing all references, cleaning the solution and reinstalling the two needed packages there is no SQLite.net available anymore.
When trying to use SQLite instead:
'SQLiteConnection' does not contain a definition for 'InsertWithChildren' and the best extension method overload 'WriteOperations.InsertWithChildren(SQLiteConnection, object, bool)' requires a receiver of type 'SQLiteConnection'
I'm curious if it's even possible to develop Android-Apps with VS seamlessly. Since everything takes years to set up.
EDIT:
Well, after some days of pain in the a** the solution was to use the even newer pre release (alpha3) which wasn't even referenced to on the official pages. Currently I'm satisfied. :)
Install-Package SQLiteNetExtensions-netstandard -Version 2.0.0-alpha3 -Pre
Hope anybody may need this.
I just solved this after doing a whole load of updates. Hit the same issues.
Uninstall ALL SQLite plugins. See attached pic/link below.
Reinstall SQLiteNetExtensions and this installs all dependencies too, actually all files in that list except SQLite.Net-PCL.
SQLiteNetExtensions installs SQLite-net-pcl but you need the other one too so, install SQLite.Net-PCL as well.
Restart Visual Studio as it doesn't always pickup all newly installed packages, the reopen your solution.
That worked for me so hopefully it'll help someone else here too.

Why can't I run my app?

My app runs perfect for desktop and Android, but robovm with libgdx will not work. I downloaded the ios sdk on my mac and got everything set up. When I try to run it on the ios simulator, I get this error:
An internal error occurred during: "Launching Gravity".
Class com.badlogic.gdx.Gdx doesn't have field gl : com.badlogic.gdx.graphics.GLCommon;
failed to resolve in superclasses and interfaces
I am not quite sure what is wrong with this. here is my code for my robovm launcher. Is there something wrong with it?
package com.me.Mercify;
import org.robovm.apple.foundation.*;
import org.robovm.apple.uikit.*;
import com.badlogic.gdx.backends.iosrobovm.IOSApplication;
import com.badlogic.gdx.backends.iosrobovm.IOSApplicationConfiguration;
public class RobovmLauncher extends UIApplicationDelegateAdapter {
protected IOSApplication createApplication() {
IOSApplicationConfiguration config = new IOSApplicationConfiguration();
config.orientationLandscape = true;
config.orientationPortrait = false;
return new IOSApplication(new GravityTwist(), config);
}
public static void main(String[] args) {
NSAutoreleasePool pool = new NSAutoreleasePool();
UIApplication.main(args, null, RobovmLauncher.class);
pool.close();
}
}
You need to update to the latest nightly build of libGDX, which contains an updated version of RoboVM which should resolve this error. LibGDX 0.9.9 depends on RoboVM 0.0.6, which is fairly outdated.

Categories

Resources