[Q] PostgreSQL connection error - Android Q&A, Help & Troubleshooting

i wanna create a connection to postgresql with jdbc.i did it with android 2.2 bu i couldt connect with android 3.2. for both application i have used the same methods but it did not connect with android 3.2.Here is the code;
public Boolean CreateConnection()
{
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
try {
conn = DriverManager.getConnection("jdbcostgresql://ip:5432/db","user", "pasword");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
return true;
}
here is the error when i tried to run my application in android 3.2;
org.postgresql.util.PSQLException: Something unusual has occured to cause the driver to fail. Please report this exception.
in addition i get the permission in the manifest.xml and i used that jar fileostgresql-8.3-606.jdbc4.jar
thanks for helping me.

Please use the Q&A Forum for questions &
Read the Forum Rules Ref Posting
Moving to Q&A

Have you figured out what your problem has been?
I have now the similar problem when switching from 2.2 to 4.0.3
It happens with the newest jdbc-Driver from postgre and also with the ssh-connection from the jsch-api.
Any suggestions?

Related

Need help troubleshooting my code.

Ok so for these last three days i have been trying to get into the android game. I did the hello android tutorial and yea. that was boring lol, so i decided to try and create a program to temporarily fix the keyboard backlight issue being experienced by some ICS port users. i have only part of the code done but it does not execute at all. I am not sure whats the problem. I have writted additional pieces to this code but have not put them in the program as i want to figure out why it doesnt run before i add more and then clean it up.
Code:
package com.dri94.led;
import java.util.*;
import java.io.*;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class LEDLightActivity extends Activity {
/** Called when the activity is first created. */
@SuppressWarnings("null")
@Override
public void onCreate(Bundle savedInstanceState) {
final int SDK_INT;
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Scanner input = new Scanner(System.in);
DataOutputStream os = null;
TextView tv = new TextView(this);
tv.setText("Enter 'y' to turn on keyboard light or 'n' to turn it off");
String yOrN = input.next();
if (yOrN == "y") {
tv.setText("Enter SDK number 7 for GB devices or 14 for ICS devices. No other devices are supported at this time");
SDK_INT = input.nextInt();
if (SDK_INT == '7') {
try {
os.writeBytes("echo 255 > /sys/class/leds/keyboard-backlight/brightness\n"
+ "chmod 444 /sys/class/leds/keyboard-backlight/brightness\n");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else {
try {
os.writeBytes("echo 255 > /sys/class/leds/kpd_backlight_en\n"
+ "chmod 444 /sys/class/leds/kpd_backlight_en\n");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
Any logcat output? I don't have ICS so those paths aren't available on my device, but similar paths are symlinks and directories. Does your app have write permissions to kpd_backlight_en (or whatever the symlink points to)?
You have a lot of problems there, lets point some of them out,
Code:
DataOutputStream os = null;
Youre initializating your outputStream as null, wich is a problem consideering you use it for writing a file. Also there are so many easier ways to write files, for example, I propose this simple writing method
Code:
public static void WriteFile(String text, String file) {
try{
FileWriter fstream = new FileWriter(file);
BufferedWriter out = new BufferedWriter(fstream);
out.write(text);
out.close();
}catch (Exception e){
//Deal exception ;D
}
}
simple code usage will be then
Code:
WriteFile("255", "/sys/class/leds/keyboard-backlight/brightness");
Second error I found, comparing strings with "==", this
Code:
if (yOrN == "y")
is wrong, you should try with
Code:
if (yOrN.equals("y")) {
Another thing i dont understand is this
Code:
final int SDK_INT;
Why do you declare a variable as final, if you are gonna assign some value later, right here
Code:
SDK_INT = input.nextInt();
Last thing I found is also comparing an integer with string? I dont understand what you do there
Code:
if (SDK_INT == '7')
Also your way to manage user inputs would be better with a simple button (or toggleButton) for turn on/off lights, or even use SensorEventListener.
I hope I have helped you in some , just tell me if you need something. Good luck!
How should i initialize it? And thank you alot. Ima play with my code tomorrow. The last one though is comparing it with a character value. but this post helped alot. I appreciate it... Especially cause i made soooo many beginner mistakes. My professor would be disappointed
Sent from my XT862 using T
Questions or Problems Should Not Be Posted in the Development Forum
Please Post in the Correct Forums
Moving to Q&A
thanks i wasnt sure where to post this! ill remember that from now on

Ping app

hey guys,
Building an app that runs a ping command at the moment and I can't quite get it to work. If I modify the command to something that isn't a terminal command then it'll output my error statement but i can't get it to display the ping output. any help would be awesome. I know my outputs for my error are bad but it's an easy way to determine what path it's outputting.
package com.mycompany.myapp;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import java.io.*;
import java.lang.Process;
public class MainActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TextView Text = new TextView(this);
Runtime runtime = Runtime.getRuntime();
try
{
Process proc = runtime.getRuntime().exec("system/bin/ping 192.168.1.1");
BufferedReader in = new BufferedReader(
new InputStreamReader(proc.getInputStream()));
String line = "null";
while ((line = in.readLine()) != null) {
Text.setText(in.readLine());
}
}
catch (Exception e)
{
String line="55";
Text.setText(line);
}
setContentView(Text);
}
}
Thanks for any help you guys can give me,
Adam
Hey,
Try using "system/bin/ping -c 1 192.168.1.1" instead.
And then add this line just after that:
Code:
proc.waitFor();
and while reading the output of the ping you might want to do it like this maybe?
Code:
String line = "";
String result = "";
while (line != null)
{
result = result + "\n" + line;
line = in.readLine();
}
Text.setText(result);
If you want to ping more than 1 packet I think it would be better to make a new thread and do proc.waitFor() in that thread. Then send a message using a handler to set the output of the ping to the TextView
k i have done that and that does make more sense but Im still getting a black screen on the output. i am testing on a Sony tab s and using AIDE (on the device) cause my eclipse is broken. this is how my code looks now,
package com.mycompany.myapp;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import java.io.*;
import java.lang.Process;
public class MainActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TextView Text = new TextView(this);
Runtime runtime = Runtime.getRuntime();
try
{
Process proc = runtime.getRuntime().exec("system/bin/ping 192.168.1.1");
BufferedReader in = new BufferedReader(
new InputStreamReader(proc.getInputStream()));
String line = "null";
while ((line = in.readLine()) != null) {
Text.setText(in.readLine());
}
}
catch (Exception e)
{
String line="55";
Text.setText(line);
}
setContentView(Text);
}
}
Is there anything else I could be missing??
Thanks,
Adam
Hey, I think you posted the same code again.
I am not sure if you can read the process stream before it is complete and ping does take a long time to complete. So your main thread is blocking on it and it doesn't get to executing the setContentView.
Thats why I think going for a seperate thread is a better option.
so it would be better to put the ping into a new class and call on it when i need it??
Not a seperate class, a seperate thread to be more specific.
Even if you do put the ping code in a seperate class' method and call that method in onCreate it will still run on the your applications main thread.
What I was trying to say is something along the lines of the following code:
Code:
private TextView textView;
private Process process;
private Handler handler;
private Thread pingThread;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
textView = new TextView(this);
textView.setText("Pinging...");
setContentView(textView);
try
{
process = Runtime.getRuntime().exec("system/bin/ping -c 5 192.168.1.1");
handler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
String result = "";
while(line != null)
{
result = result + "\n" + line;
line = reader.readLine();
}
reader.close();
textView.setText(result);
}
catch(Exception e)
{
e.printStackTrace();
textView.setText("Error");
}
}
};
pingThread = new Thread()
{
@Override
public void run()
{
try
{
process.waitFor();
}
catch(Exception e)
{
e.printStackTrace();
}
handler.sendEmptyMessage(0);
}
};
pingThread.start();
} catch (Exception e)
{
e.printStackTrace();
}
}
I am not sure if this is exactly how you want your app to behave. There might be a better way of doing what you want than what I have suggested but I tested the above code and it works for me.
thats wicked, basically what want my program to do is to run a ping command through a usb to rj45 adapter. at the moment I just need it to do the ping command through wifi and once that was working I was going to set it up to go through usb.
I wonder if there's something I'm doing wrong like I'm build the apk in AIDE on the tablet or something, cause I'm still getting a black screen when booting the app.
If I error the code up a bit, Like put "system/bin/pi ....." instead I do get pinging on the app but no error output and if the code is fine then nothing displays
That is very strange :S.
If you use the incorrect command it works fine but when you use the correct command it doesn't?
Can you post your code? or provide more details if possible?
the code is just the code you posted cause I thought if a I could get it working with that code then modify it to what it needs to do, when the command is incorrect it displays "ping....." but doesn't display an error, I'm going to install eclipse and build the package with that and see how it goes. did you test on a tablet and what did you use to deploy the package?
Adz117 said:
the code is just the code you posted cause I thought if a I could get it working with that code then modify it to what it needs to do, when the command is incorrect it displays "ping....." but doesn't display an error, I'm going to install eclipse and build the package with that and see how it goes. did you test on a tablet and what did you use to deploy the package?
Click to expand...
Click to collapse
I think i know whats happening. It isnt the Ide and using eclipse wont make much of a difference.
Are you usIng something like -c 5 in the ping command? Cause if you aren't i think ping is Going to take a really long time and all you'll see on the screen is "Pinging..."
Yea I have got that in the command, when the code is correct and working I dont get anything all I get is a black screen. Its when I error the command up a bit that I get pinging
Sent from my Sony Tablet S using XDA
hey guys,
just got eclipse running and tested it on an avd emulator and it runs perfect, so the question is what would cause it not to run on my tablet?
I have no idea! I don't have access to an Android Tablet, so I can't test it out! I tested it out on my phone too and it works just fine.
One thing I can suggest though is:
Put log statements throughout the program to signify where the the control has reached. Then run it on your tablet. That should shed some light on where the code is failing on your tablet.
tested it on my phone which is running 2.3 and it failed on there as well, "ping......" would pop up for about a second then disappear, also if I use a command like ls instead of ping on my tablet it will work perfectly fine so I'm guessing for some reason past android 2.1 it doesn't like the ping command. any ideas?
I tested it out on phone with 2.2. Did you try putting log statements and checking where it is failing.
You could also add breakpoints in your code and run it?

[Q] How can I access my preference?

I created a Xposed module with a SettingsActivity. Users can set what they want in SettingActicity.
Now I want to read my preference in hooking process.So I wrote these in SettingActicity:
Code:
getPreferenceManager().setSharedPreferencesMode(MODE_WORLD_READABLE);
getPreferenceManager().setSharedPreferencesName("com.me.myapp");
addPreferencesFromResource(R.xml.pref_general);
And these in a class which used to hook method:
Code:
@Override
public void initZygote(IXposedHookZygoteInit.StartupParam startupParam) throws Throwable {
prefs = new XSharedPreferences("com.me.myapp");
prefs.makeWorldReadable();
}
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
prefs.reload;
if (prefs.getInt("policy", -1) == 1) { // policy is a keyname which is defined in PreferenceScreen
// do something
}
But it can't read anything.So it always return default value.
And I got prefs.getAll().size() is 0.
I checked /data/data/com.me.myapp/shared_prefs, there is a xml file named com.me.myapp.xml .Its permission is 664.But I still can't read my preference.
Any ideas to solve it? Thanks in advance.
PS:I'm using Android Studio to build this module.

BT Pan Android

Hey guys,
Let me start by introducing myself. I am Alcanzer, a small time, new to the game, android developer. I'm working on a project that requires Bluetooth Pan to access the internet from a raspberry pi. I tried a few code snippets from Stack Overflow but I keep running into exceptions regarding tethering permissions. I set the permissions in manifest but I think I need to request them programmatically. Does anyone know how to request tethering permissions programmatically?(I would've posted my StackOverflow link here, but I'm not sure about the XDA rules regarding outgoing links).
I'm happy to provide any other information regarding this problem of mine.
Thank you!
Tethering
Since Android 6.0 (API 23) users grant permissions to apps while the app is running, not when they install the app.
You need at least two permissions:
CHANGE_NETWORK_STATE
WRITE_SETTINGS
Example code to ask permissions:
Code:
ActivityCompat.requestPermissions(new String[]{Manifest.permission.WRITE_SETTINGS}, MY_PERMISSIONS_REQUEST_WRITE_SETTINGS);
// override onRequestPermissionResult method in your activity
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_WRITE_SETTINGS: {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission granted
} else {
// permission denied
}
}
}
}
FSP Dev said:
Since Android 6.0 (API 23) users grant permissions to apps while the app is running, not when they install the app.
You need at least two permissions:
CHANGE_NETWORK_STATE
WRITE_SETTINGS
Example code to ask permissions:
Code:
ActivityCompat.requestPermissions(new String[]{Manifest.permission.WRITE_SETTINGS}, MY_PERMISSIONS_REQUEST_WRITE_SETTINGS);
// override onRequestPermissionResult method in your activity
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_WRITE_SETTINGS: {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission granted
} else {
// permission denied
}
}
}
}
Click to expand...
Click to collapse
Thanks for your fast reply, and sorry for my late one.
Just one question, would these 2 permissions enable me to use the Bluetooth pan/tethering? Forgive my naivety but camera has permission.camera, internet has permission.internet and so on.
Thank you!
Bump!

Programatically Disable The Audio on Headset

I am trying to disable the headset on Marshmallow in order to get around the "disable USB audio routing" selection in the developer options. This works perfectly fine on API23
Code:
public void enableUsbRouting(int state) {
Globals.log("=============== enableUsbRouting: " + state);
try {
int deviceType = DEVICE_OUT_USB_DEVICE;
// turn off headset
Class<?> cl = Class.forName("android.media.AudioManager");
Method method;
method = cl.getMethod("setWiredDeviceConnectionState", new Class[]{Integer.TYPE, Integer.TYPE, String.class, String.class});
method.invoke(mAudioManager, new Object[]{deviceType, state, "device", ""});
} catch (Exception e)
{
e.printStackTrace();
}
}
This however isn't working now on API24 Nougat and beyond. Is this code now deprecated as cannot find anything on it.
Thanks

Categories

Resources