I'm trying to connect my android application to my oracle 10g DB, i'm using JDK 1.6, OJDBC14.jar and working on a 4.+ application. I used to have a few problem with the driver but here comes the best one : after excecuting this code :
String url="jdbc:oracle:thin:usr/pwd#r2d2.iut-orsay.u-psud.fr:1521:etudom";
Connection co = null;
try {
Class.forName("oracle.jdbc.OracleDriver");
popUp("Driver Ok");
}
// Should never happend
catch (ClassNotFoundException e){
popUp("ERROR: Driver's missing");
//System.exit(1);
}
// Unknow problem
catch (Exception e){
popUp("ERROR : " + e.getMessage() + "\nFrom: " + e.getCause());
}
try {
co = DriverManager.getConnection(url);
popUp("Connection ok");
}
// In case of internet problem
catch (SQLException e) {
popUp("Throw from SQLException\nERROR : " + e.getMessage());
//System.exit(1);
}
// unknown problem
catch (Exception e){
popUp("ERROR from getConnection :\nMessage: " + e.getMessage() + "\nFrom: " + e.getCause() + "\nMessage extra: "+e.getLocalizedMessage());
}
And I've got a popUp like that :
ERROR from getConnection :
Message: null
From: null
Message extra: null
No output in the log or in the console.
I'm literaly lost
Any help would be great!
Ps: sorry for my bad english.
The reason why you are not able to connect the device to your Oracle DB is, mobile devices are not equipped to carry out such actions as they are not built with drivers for the vast amount of Databases that are out there. However, in order to connect your app to the Oracle DB you have to create what is called a Web Service or an API to get the job done. Check out these tutorials they should get you rolling:
How to connect Android with PHP, MySQL (the concept here is the same, just use your Oracle DB instead)
Oracle Mobile Database server
Android to Oracle connectivity through java
Related
I'm using Sharp.Xmpp to receive upstream messages from Android Device via FCM. It connects fine and 'at times' I can receive the messages sent from Android on my app server but the ratio is 50% whereas Android device gives a successful onMessageSent event.
The server side code is:
try {
using (var cl = new XmppClient("fcm-xmpp.googleapis.com", "Username", "Password", 5236, Sharp.Xmpp.Core.TLSMode.TLSSocket)) {
// Setup any event handlers before connecting.
cl.Message += OnNewMessage;
// Connect and authenticate with the server.
cl.Connect();
SendPushNotification("Connected");
cl.Close(); }
}
catch (InvalidOperationException ex) { SendPushNotification("Error Invalid: " + ex); }
catch (IOException ex) { SendPushNotification("Error IO: " + ex); }
catch (XmppException ex) { SendPushNotification("Error XMPP: " + ex); }
catch (NullReferenceException ex) { SendPushNotification("Error Null: " + ex); }
New Message Received event is
private void OnNewMessage(object sender, Sharp.Xmpp.Im.MessageEventArgs e) {
SendPushNotification("Message from " + e.Jid + " " + e.Message.Body);
div_View_Message.InnerHtml = "Message xyz " + e.Message.Body.ToString();
//throw new NotImplementedException();
}
and the SendPushNotification(String str) is Downstream messages with HTTP protocol. Android Device receives a push notification of 'connected' fine but the 'e.Message.Body' is received at times and not others. What should be added/removed?
Android Sends the messages as
FirebaseMessaging.getInstance().send(new RemoteMessage.Builder("SENDER_ID#gcm.googleapis.com")
.setMessageId(Integer.toString(INT_VALUE)).addData("my_token", str).build());
As mentioned in the accepted answer to this question, XMPP must stay open at all times. Hence, switching for Web based application, that closes the connection after every few requests per second, to a Desktop application, hosted on a local server, solved the issue.
Also, it adding setTtl(86400); for message sending ensures onMessageSent call.
Here's what I'm using:
Openfire 3.10.2
Smack 4.1.3
Environment: Android
I'm trying to search for a registered user, but I kept failing to do so. I've tried so many different combinations. I also tried on an older version of smack.
Here's my latest modified code:
UserSearchManager userSearchManager = new UserSearchManager(connection);
Form searchForm = null;
List<ReportedData.Row> list = null;
try {
userSearchManager.getSearchForm("search." + connection.getServiceName());
Form answerForm = searchForm.createAnswerForm();
answerForm.setAnswer("Username", true);
answerForm.setAnswer("search", userName);
answerForm.setAnswer("Name", true);
answerForm.setAnswer("search", userName);
ReportedData data = userSearchManager.getSearchResults(answerForm, "search." + connection.getServiceName());
list = data.getRows();
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
Log.e(LOG_TAG, e.getMessage());
} catch (SmackException.NotConnectedException e) {
Log.e(LOG_TAG, e.getMessage());
}
I would get this error
org.jivesoftware.smack.XMPPException$XMPPErrorException: XMPPError: remote-server-not-found - cancel
on line,
Form searchForm = manager.getSearchForm("search." + connection.getServiceName());
I don't know if I missed configure something on openfire server, or do I need to setup something before I start searching.
My workaround idea was to get the full list of registered users and then search from there, but I'm not sure how to achieve that.
Once I logged in, the roster only consists of my friends and groups.
Could someone point me to the right direction?
You're trying to search for users on the server "search." + connection.getServiceName(), but your server is telling you that it can't find that server. It looks like you did not set up a search server in OpenFire, or you're using the wrong address.
I am very new to Android Development and Java,
I have C# experience
anyway
I am trying to get XML from a URL
I tried every possible thing but non is working.
Always get crash or no result.
I just want a simple XML result, I found some JSON and PHP code, that i do not want to connect to MySQL.
is there any simple function to retrieve the XML as string from a URL
this is one of my traials
`
lbl1 = (TextView) findViewById(R.id.lbl1);
try {
InputStream is = new URL("http://api.androidhive.info/pizza/?format=xml").openConnection().getInputStream();
String strxml = is.toString();
lbl1.setText(strxml);
}
catch (MalformedURLException e) {
System.out.println("Error: " + e.getMessage());
e.printStackTrace();
}
catch (IOException e) {
System.out.println("Error: " + e.getMessage());
e.printStackTrace();
}`
any help will be much appreciated. Thanks
How would you do it in C#?
URL.toString() and (in c#) Request.Url.ToString() are alike. Both behave the same way: creating a string of the URL.
(Like in C#) you would need a HTTP client: http://android-developers.blogspot.de/2011/09/androids-http-clients.html
I'm attempting to send notifications to Sony LiveWare devices
I've installed: com.sonyericsson.extras.liveware.extension.notificationsample, but I get errors and exceptions while trying to run it:
Load the preference activity onto the device
Check "Active" on the preferences screen
The following method is called in SampleExtensionService:
private void addData() {
Random rand = new Random();
int index = rand.nextInt(5);
String name = NAMES[index];
String message = MESSAGE[index];
long time = System.currentTimeMillis();
long sourceId = NotificationUtil
.getSourceId(this, EXTENSION_SPECIFIC_ID);
if (sourceId == NotificationUtil.INVALID_ID) {
Log.e(LOG_TAG, "Failed to insert data");
return;
}
String profileImage = ExtensionUtils.getUriString(this,
R.drawable.widget_default_userpic_bg);
ContentValues eventValues = new ContentValues();
eventValues.put(Notification.EventColumns.EVENT_READ_STATUS, false);
eventValues.put(Notification.EventColumns.DISPLAY_NAME, name);
eventValues.put(Notification.EventColumns.MESSAGE, message);
eventValues.put(Notification.EventColumns.PERSONAL, 1);
eventValues.put(Notification.EventColumns.PROFILE_IMAGE_URI, profileImage);
eventValues.put(Notification.EventColumns.PUBLISHED_TIME, time);
eventValues.put(Notification.EventColumns.SOURCE_ID, sourceId);
try {
getContentResolver().insert(Notification.Event.URI, eventValues);
} catch (IllegalArgumentException e) {
Log.e(LOG_TAG, "Failed to insert event", e);
} catch (SecurityException e) {
Log.e(LOG_TAG, "Failed to insert event, is Live Ware Manager installed?", e);
} catch (SQLException e) {
Log.e(LOG_TAG, "Failed to insert event", e);
}
}
The first problem is that "long sourceId = NotificationUtil.getSourceId(this, EXTENSION_SPECIFIC_ID)" returns -1
I'm not sure how to change, but the docs say it is an optional field. So I removed it to see if I could get any further:
When removing the sourceId code I get an exception on the insert call:
"java.lang.SecurityException: You do not have sufficient permission to perform a insert"
My Environment:
HTC One V paired with a LiveView wrist pager
http://www.amazon.co.uk/Sony-Ericsson-0001516170-LIVE-VIEW/dp/B00477X6DA
I've got the followings apps installed
LiveView
SmartConnect(LiveWare Manager)
I'd appreciate any help getting this sample to work or if anyone knows of a more straight forward approach to doing simple text notifications for LiveWare.
EDIT:
Made some progress. Found an emulator here:
android-sdk\add-ons\addon-sony_add-on_sdk_1_0-sony-16\apk_files
I installed that on the phone. The "SampleExtensionService" works fine in the emulator.
My assumption now is that add-on sample is not compatible with the LiveView device.
The LiveView is unfortunately not supported by the SmartExtension APIs. Instead, there is a specific developer kit for the LiveView here.
If you would, in the future, buy a newer wearable device from Sony Mobile, a notification extension based on the Smart Extension APIs would be usable for several devices including SmartWatch, SmartWatch 2, SBH50, SBH52 etc.
I am working with android 4.1.1, IDE= eclipse, and SQL Server 2008.
Device= Note 2
android:minSdkVersion="10"
When I run the code snippet on the UI thread It gives me the error "Unable to get information from SQL Server:", but if I run the code in a background thread or AsyncTask Thread it works. Any help in understanding the two processes would be greatly appreciated?
Note: "The issue occurred when I upgrade the minSDKVersion from 8 to 10."
public Boolean open() {
Boolean res = false;
try {
String s = "jdbc:jtds:sqlserver://" + "xx.xxx.x.xx" + "/" + "FOO" + ";instance=SQLEXPRESS";
Class.forName("net.sourceforge.jtds.jdbc.Driver");
con = DriverManager.getConnection(s, "UserFoo", "1234");
res = true;
} catch (SQLException sx) {
Log.e(TAG, "DB:Open - " + sx.toString());
} catch (ClassNotFoundException e) {
Log.e(TAG, "DB:Open - " + e.toString());
}
return res;
}
Starting with Android 3.0, trying to access the network on the main (UI) thread results in:
NetworkOnMainThreadException
I'm guessing that you didn't see it because somewhere higher in your call stack you have:
catch (Exception)
which leads to:
"Unable to get information from SQL Server:"
As you have already discovered, a separate thread is the solution.