Hi,
I need help by using XML-RPC on Android. The Software I want to write needs to get Informations via XML-RPC from a Server. I have no expirience by Using XML-RPC and so I dont no wants the best way to do what I want.
Does someone have a good tutorial for that or give me some tips?
I tried do do it like that, but always getting an unknownHostException
PHP:
String testString;
try {
uri = URI.create("htt://julre.servebeer.com:7227");
client = new XMLRPCClient(uri);
testString = (String)client.call("free_space");
} catch (Exception e) {
// TODO: handle exception
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
The "p" by http I had to delete, because I cant post outsite URLs yet...
EDIT:
Ok the first problem I solved. I have forget to set the persmission for the internet access^^
Now i become the HTTP Status 401 != 200....
here is a code, i have a basic login screen and if username is correct it need to swiitch to AndroidTab.java view, i cant write a correct code for it any one can help ?
Code:
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]btnLogin[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setOnClickListener([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] OnClickListener() {[/SIZE]
[LEFT][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464] @Override[/COLOR][/SIZE][/COLOR][/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055] public [/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onClick(View v) {[/SIZE]
[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f] // Check Login[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2] String username =[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]etUsername[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getText().toString();[/SIZE][/LEFT]
[/LEFT]
[LEFT][SIZE=2] String password = [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]etPassword[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getText().toString();[/SIZE][/LEFT]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055] if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](username.equals([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"User1"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) && password.equals([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"pass"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])){[/SIZE]
[LEFT][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0] lblResult[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setText([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Login successful."[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE][/LEFT]
[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* ************************************[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]* ************************************[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f]
[SIZE=2][COLOR=#3f7f5f]* [/COLOR][/SIZE]
[SIZE=2][COLOR=#3f7f5f]* [/COLOR][/SIZE]
[SIZE=2][COLOR=#3f7f5f]* CODE TO GO TO AndoidTab VIEW Class[/COLOR][/SIZE]
[SIZE=2][COLOR=#3f7f5f]* [/COLOR][/SIZE]
[SIZE=2][COLOR=#3f7f5f]* ************************************[/COLOR][/SIZE]
[SIZE=2][COLOR=#3f7f5f]**************************************/[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
[/LEFT]
[SIZE=2][COLOR=#3f7f5f]
[/COLOR][/SIZE]
[LEFT][SIZE=2]} [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]else[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] {[/SIZE]
[LEFT][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]lblResult[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setText([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Login failed. Username and/or password doesn't match."[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2] }[/SIZE]
[SIZE=2] }[/SIZE][/LEFT]
[SIZE=2]});[/SIZE][/LEFT]
(if u full code neccessery i can add it)
Look up Intent & startActivity(); there are alot of examples out there.
jug6ernaut said:
Look up Intent & startActivity(); there are alot of examples out there.
Click to expand...
Click to collapse
i know and im looking for an answer online too,
but atm i really could do with a quick fix lol
one learns nothing if everything is handed to them
With that said xD.
Code:
Intent myIntent = new Intent();
//being package name & activity name
myIntent.setClassName("jug6ernaut.lwp.tetris", "jug6ernaut.lwp.settings.ColorSettings");
startActivity(myIntent);
note that the activity will have to be identified in you manifest file.
also note that if you are not going to use your life first activity anymore you will probably want to remove it from the activity stack so that when you press the back button it doesnt reopen it.
Google has always limited the access to several features like GPS on/off management, PIN control and more to third party applications. Sometimes the developers have taken advantage of certain security bugs to circonvent those limitations, but Google has fixed those bugs on the latest OS version.
There are certain functions that in my opinion should be allowed because the security risk is minimun, like GPS control and SIM PIN entering , so I've wr1tten a small app to open this possibility. It does nothing by itself and is not normally loaded but registers for specific intents and when received does those forbidden functions.
Any thir party application can take advantage of it, no need to ask for permisions. Simply broadcast and intent and voila!
Sample usage code:
Code:
public static final String TOOGLE_GPS = "com.beemer.secholeutils.TOOGLE_GPS";
public static final String ENTER_PIN = "com.beemer.secholeutils.ENTER_PIN";
public static final String EXTRA_PIN = "com.beemer.secholeutils.EXTRA_PIN";
public void toogleGPS() {
Intent intent = new Intent(TOOGLE_GPS);
sendBroadcast(intent);
}
public void enterPIN(String PIN) {
Intent intent = new Intent(ENTER_PIN);
intent.putExtra(EXTRA_PIN, PIN);
sendBroadcast(intent);
}
Disclaimer
I'm nor responsible of what happens to your device if you install this apk or while you install it.
Installing this app could allow any third party app to use it to turn on/off the GPS or enter your SIM PIN (if known) even try an brute force atack without asking for permission.
The app must be installed as a system app. You can do it manually but from kitkat on it has became somewhat difficult. I recomend installing busybox and systemappmover from Play store:
https://play.google.com/store/apps/details?id=stericson.busybox
https://play.google.com/store/apps/details?id=de.j4velin.systemappmover
Install secHoleUtils.apk as a normal app and use SystemAppMover to make it a system app.
DEBUG
In order to debug your app, SecHoleUtils will log the calls and errors if they happens:
Code:
pre-KitKat
Log.i("SecHoleUtils", "Received " + TOOGLE_GPS + " intent");
Kitkat:
Log.d("SecHoleUtils", "ToogleGPS. Current mode: " + currentMode + " newMode: " + newMode);
Log.e("SecHoleUtils", "Error toogling GPS");
Log.i("SecHoleUtils", "Received " + ENTER_PIN + " intent");
Log.e("SecHoleUtils", "Error inserting PIN");
Detection of the APK
In order to detect in your app if SecHoleUtils is installed and you can use it, there is a sample code:
Code:
//Test if SecHoleUtils.apk is installed
boolean bSecHoleUtils = false;
try {
getPackageManager().getPackageInfo("com.beemer.secholeutils",PackageManager.GET_META_DATA);
bSecHoleUtils = true;
}
catch (NameNotFoundException e1){}//Not installed. No need to do anything.
If I see interest in the app, I'll add more APIs to it.
I'm trying to access the hidden API for Phone.class to switch the preferred network mode via reflection.
I know this is not safe for porting to other android versions/roms and requires a system app to hold permission WRITE_SECURE_SETTINGS.
I Already managed to switch data via reflection and toggle gps via Settings.Secure.putString() by moving my app to system partition, so i think this should work too.
Does anyone have experience with reflection and/or root and is willing to help?
Of course I will share all my code/findings here.
Thanks in advance!
Links:
http://stackoverflow.com/questions/8607263/android-4-0-4g-toggle
http://stackoverflow.com/questions/5436251/how-to-access-setpreferrednetworktype-in-android-source
You can achieve this with a simple sqlite3 query instead of bothering with java reflection
Here's how :
In a terminal :
To enable 2G only
Code:
su
sqlite3 /data/data/com.android.providers.settings/databases/settings.db
insert into global values(null, 'preferred_network_mode', 1);
.exit
To enable 2G & 3G :
Code:
su
sqlite3 /data/data/com.android.providers.settings/databases/settings.db
insert into global values(null, 'preferred_network_mode', 0);
.exit
In java :
Example to enable 2G only (just replace the 1 with a 0 in the insert into to enable 2G & 3G)
Code:
try {
Process process = null;
process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(
process.getOutputStream());
os.writeBytes("sqlite3 /data/data/com.android.providers.settings/databases/settings.db" + "\n");
os.writeBytes("insert into global values(null, 'preferred_network_mode', 1);" + "\n");
os.writeBytes(".exit" + "\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
It might require a reboot to be active though, not sure
If it doesn't work on your rom (tested on cm10.1), it might be a different row name, try investigating your settings.db like this :
Code:
sqlite3 /data/data/com.android.providers.settings/databases/settings.db
.tables [COLOR="Green"]// returns all the tables[/COLOR]
select * from [I]tablename[/I]; [COLOR="green"]// in cm10.1 it's in [I]global[/I] but otherwise look in [I]secure[/I] and/or [I]system[/I]
// this command returns all the rows from the selected table, the names are usually explicit, so you should find the setting you're looking for[/COLOR]
Then, when you found it :
Code:
insert into [I]tablename[/I] values(null, [I]'row name'[/I], value);
Thanks, this is very helpful!
I think you are right, one will need to tell the system to update the settings or send a broadcast that this setting has changed (like for airplane mode).
I will look at the CM sources to find out what i can do.
superkoal said:
Thanks, this is very helpful!
I think you are right, one will need to tell the system to update the settings or send a broadcast that this setting has changed (like for airplane mode).
I will look at the CM sources to find out what i can do.
Click to expand...
Click to collapse
Glad it helped.
If you manage to find a way to make the settings read the db without a reboot, please share your findings, would be very useful.
Androguide.fr said:
Glad it helped.
If you manage to find a way to make the settings read the db without a reboot, please share your findings, would be very useful.
Click to expand...
Click to collapse
Of course i will!
Buddy... you can toggle network mode with intent, no root needed, nor permissions!!
HereĀ“s entire sample:
Code:
package com.serajr.togglenetworkmode;
import android.os.Bundle;
import android.provider.Settings.Secure;
import android.provider.Settings.SettingNotFoundException;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bnt = (Button) findViewById(R.id.button1);
bnt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// toggle
toggleNetworkMode();
}
});
}
private void toggleNetworkMode() {
int mode = getCurrentNetworkMode() + 1;
if (mode > 2) {
mode = 0;
}
// 0 = 3G_ONLY
// 1 = 3GSM_ONLY
// 2 = 3G_PREFERRED
// change mode
Intent intent = new Intent("com.android.phone.CHANGE_NETWORK_MODE");
intent.putExtra("com.android.phone.NEW_NETWORK_MODE", mode);
sendBroadcast(intent);
}
private int getCurrentNetworkMode() {
try {
int current = Secure.getInt(getContentResolver(), "preferred_network_mode");
return current;
} catch (SettingNotFoundException ex) {
return 0;
}
}
}
Try it and tell me later!!!
Thanks, but this will only work if your phone.apk has an exported receiver for this intent.
This is only the case if you or your rom dev modded it to be so.
Some custom ROMs also have this kind of "mod/bug" in the power widget, allowing you to toggle gps.
I tried it with slim bean 4.2 build 3 on i9000 and as expected it didn't work (and so will most likely in CM10.1 too).
Just too good to be true!
If youre following the root method Use RootTools for that
sak-venom1997 said:
If youre following the root method Use RootTools for that
Click to expand...
Click to collapse
Thanks, I already do.
Really helpful library!
And yes, I will do it by sql injection to settings.db
I only need to figure out what broadcasts have to be sent / methods called and if this is possible.
Argh I am kinda lost in CM sources.
Can anyone point me to the place where this is handled?
I managed to toggle flight mode by using this in a SU shell:
Code:
if(settingenabled)
{
executeCommand("settings put global airplane_mode_on 1");
executeCommand("am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true");
}
else
{
executeCommand("settings put global airplane_mode_on 0");
executeCommand("am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false");
}
Interstingly enough it didn't work if i manually injected the value and then sent the broadcast.
I have no idea why.
So atm I'm trying to do the same thing for preferred_network_mode. I can write the value to settings.db, but I just don't know what i have to do to make the system apply the setting yet.
EDIT: shell binary "settings" only works in android 4.2 (and probably upwards)
So i finally found it in CM Sources.
Seems like we need to get the currently running Instance of the Phone class to notify it about the change.
Also seems like we are back to reflection, as this is an internal system class.
I also killed com.android.phone process after updating the setting, but that didn't change anything.
EDIT:
1st step towards reflection:
I figured out that i need a jar file from the cm build to use system classes via reflection.
Does anyone have more information about this?
superkoal said:
So i finally found it in CM Sources.
Seems like we need to get the currently running Instance of the Phone class to notify it about the change.
Also seems like we are back to reflection, as this is an internal system class.
I also killed com.android.phone process after updating the setting, but that didn't change anything.
EDIT:
1st step towards reflection:
I figured out that i need a jar file from the cm build to use system classes via reflection.
Does anyone have more information about this?
Click to expand...
Click to collapse
Just a far fetched guess, but maybe try to add /system/framework/framework.jar from your rom to your app's build path
Is a reboot that unacceptable in your case ?
Maybe it's just the challenge, but i wanna change it like every other setting
A reboot is very far from what i call comfortable
superkoal said:
Maybe it's just the challenge, but i wanna change it like every other setting
A reboot is very far from what i call comfortable
Click to expand...
Click to collapse
Yeah, I get what you mean^^^
Here's a good (but old, 2009^^) official Android tutorial from the Android devs on reflection if it can help you : http://android-developers.blogspot.fr/2009/04/backward-compatibility-for-android.html
So i got some news
1. This setting is heavily protected by android system and can only be modified by the phone process itself
2. Some roms have a modified phone apk listening to a broadcast, enabling 3rd party apps to toggle
http://forum.xda-developers.com/showthread.php?t=1731187
3. His Majesty Chainfire started an app project which could amongst other features also toggle 2g/3g, but he gave up development. Regarding 2g/3g he implemented several methods, one of them being RIL injection, which he described as a really hard hack and highly experimental.
http://forum.xda-developers.com/showthread.php?t=807989
Seems this task is not that easy
But i found out that tasker can toggle 2g/3g on my phone (running slim bean 4.2.2), this is when i found out about the modified phone.apk from 2). So I'mcomfortable that it's working on my phone and i can at least develop an app for myself
Sent from my GT-I9000 using xda app-developers app
I'm making a project in Android Studio that requires the user to give permissions. The only code that I've found online and in YouTube tutorials is the following code:
public void onClick(View v) {
Intent i = new Intent();
i.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
i.setData(Uri.parse("package:" + getPackageName()));
i.addFlags(Intent.FLaG_ACTIVITY_NEW_TASK);
startActivity(i);
}
It works however, I would like a direct code that will open permissions directly for my app. Not just the details. I know it's one click over but I would still like a direct code that will popup that permissions area at users request. I appreciate the help that I can get with this.