Ksoap2 not working on all versions of android - android

I have developed a simple client server android application. I have created the application to work on all versions of android. So I have given this code on androidmanifest.xml file.
<uses-sdk android:minSdkVersion="10"
android:targetSdkVersion="16"/>
For establishing connectivity I have used this jar file (ksoap2-android-assembly-2.5.8-jar-with-dependencies) in my application. The problem now is that the application works fine and error free on android versions upto gingerbread. But when I try to run it on versions above that, the app does not work, not even tries to send data to the server, whereas on gingerbread and below, it client and server communication works fine. What is the possible problem for this error. Is it because of the jar file which I'm using. For establishing the client server communication I have imported the following in my project.
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

Use of AsyncTask in my application solved it. Or else you can use the following code in your mainactivity below setcontentview
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
This is not a recommended way of solving this kind of errors in android, but at times when you are needy, you can use it. But I would not recommend doing this.

Related

SSL in Kivy for android development

I was developing a mobile app that can send mqtt messages to AWS Iot. It needs paho-mqtt library. It can be included in buildozer.spec requirements. My problem is in the SSL part, because I need to import SSL in the code which seems to have a problem with the python version running in python-for-android, which is 2.7.2.
The code is below, which works fine on the PC, but on th phone it is not working.
from kivy.lang import Builder
from kivy.app import App
from kivy.uix.label import Label
import paho.mqtt.publish as mqtt
import paho.mqtt.client as mqttclient
#
class MqttTest(App):
def build(self):
topic = "topic1"
my_ca_cert = "RootCA.pem"
my_pri_cert = "my.cert.pem"
my_key_cert = "my.private.key"
try:
import ssl
mqttc = mqttclient.Client("Python_Ex_Pub")
mqttc.tls_set(my_ca_cert,
certfile=my_pri_cert,
keyfile=my_key_cert,
cert_reqs=ssl.CERT_REQUIRED,
tls_version=ssl.PROTOCOL_TLSv1_2,
ciphers=None)
mqttc.connect("myaddress", 8883)
mqttc.publish(topic, "This is a test pub from Python.")
return Label(text="Hi it works!")
except Exception as e:
import traceback
a=traceback.format_exc()
try:
f1=open("/storage/emulated/0/Download/err.txt","w")
f1.write(str(a))
f1.close()
except:
pass
return Label(text=str (a))
if __name__ == '__main__':
MqttTest().run()
without adding anything related to SSL in buildozer.spec requirements, I get the following error:
no module named _ssl
If I added openssl as one of the requirements, then I get the following error:
'module' object has no attribute 'PROTOCOL_TLSv1_2'
As noted PROTOCOL_TLSv1_2 was added in later Python 2 version than p4a provides.
You can try to build apk with Python 3:
Change your buildozer's requirements line replacing python2 with python3crystax
Download and unpack crystax ndk here
Change your buildozer's android.ndk_path to point unpacked crystax ndk directory
Run buildozer android debug
If you're lucky enough you'll be able to build apk with Python 3 without any other actions.
I encountered the similar issue. I am trying to import pydrive without doing anything at first. Below is from logcat.
I tried 3 os environment, osx, ubuntu, bulldozer vm. All give me the same error.
I/python (13323): File "/Users/macuser/test/.buildozer/android/platform/build/dists/myapp/private/lib/python2.7/site-packages/httplib2/init.py", line 960, in
I/python (13323): AttributeError: 'module' object has no attribute 'HTTPSConnection'
In httplib.py, i found below code.
try:
import ssl
except ImportError:
pass
else:
class HTTPSConnection(HTTPConnection):
"This class allows communication via SSL."
So I suspect ssl not import successfully. Then, check ssl.py and found PROTOCOL_SSLv3 cannot import successfully.
from _ssl import PROTOCOL_SSLv3, PROTOCOL_SSLv23, PROTOCOL_TLSv1
Until here i am not able to proceed further. I am using python3crystax and it still not work as claim in this post.
Since buildozer will download all library separately, i suspect python automatically downloaded by bulldozer is a python version that doesn't include ssl3 support.

import file with Kivy/Buildozer

I'm trying to import file with buildozer but I can't know how
what I'm doing : in main.py there is
import xmpp
And it's should import this from file named : xmpp
it's working 100% but when I'm trying to make it an android app it isn't working
What should I do?

internal app can not import com.android.internal.policy.impl?

I added an app in packages/apps in android build system and my app use some internal api.But when I use mm or mmm to make the app,android build system shows error:package com.android.internal.policy.impl does not exist etc.But I saw Phone app also uses internal api like com.android.internal.xx and it builds with no errors.I want to know whether there are something i missed and how can i use internal api in internal apps.BTW,my app can import com.android.internal.telephony,but cannot import com.android.internal.policy.impl.Thanks.
Finally I add LOCAL_JAVA_LIBRARIES := android.policy framework in Android.mk, and it works.

Android schema validation with xerces

I am trying to validate an xml file against an xsd schema file using Xerces. I am hitting errors that I am unable to resolve, below is the logcat output. Please note that trying the same code and xercesImpl.jar file in a java application produces accurate validation results but moving the same to android results in errors. Please advice.
E/AndroidRuntime(792): java.lang.NoClassDefFoundError: org.apache.xerces.parsers.SAXParser
Thanks..
The solution is to use Apache Xerces ported to Android.
There is a project here
You have to do a svn chekout and export the proyect to a jar file to use as a library in your android proyect.
The code to instance SchemaFactory change a little.
I show you an example:
import mf.javax.xml.validation.Schema;
import mf.javax.xml.validation.SchemaFactory;
import mf.javax.xml.validation.Validator;
import mf.org.apache.xerces.jaxp.validation.XMLSchemaFactory;
SchemaFactory factory = new XMLSchemaFactory();
Schema esquema = factory.newSchema(".../file.xsd");
The problem is that android doesn't have xerces and validating interface =)
But you can simply add validating from xerce:
You can use xerces and native schema validation (in java) in adnroid - you have to download xerces sources and (after some simple manipulations) include it to your own code - you will be able to use DocumentBuilderFactory.setShema method.
https://stackoverflow.com/questions/13142567/xml-schema-validation-xmlsignature-with-xerces-in-android

OData class not found when trying to access SQL Azure database

I am trying to create an android application to connect to Azure's SQL database. When I try to create a ODataConsumer object that would later be used to filter the message.
The ODataConsumer object is create with the create method
ODataConsumer c = ODataConsumer.create("http:/xxx/yyy.svc");
But when the execution reaches here, I get class def not found exception and the application is force closed.
I downloaded the jar files from the following site
http://code.google.com/p/odata4j/downloads/list
I started off with v0.3 as this is the jar file used in the demo that is provided by Microsoft. I also tried v0.4
I add <uses-permission android:name="android.permission.INTERNET"/> to the manifest file of the project. I also import
import org.odata4j.consumer.ODataConsumer;
import org.odata4j.core.OEntity;.
Am I missing something here?
The error that I get is AndroidRuntime(595): java.lang.NoClassDefFoundError: org.data4j.consumer.OdataConsumer
You should really be using the latest version.
Also the class name in the error is misspelled. It's ODataConsumer not OdataConsumer.
I was having the same problem. In my case I was able to follow the example here:
http://xrigau.wordpress.com/2012/03/22/fix-some-problems-with-libraries-in-the-adt-17-plugin-10/
which is described here:
Android-SDK r17 ruins working projects
which solved my problem. Good luck.

Categories

Resources