I have created a login and register system, when ever I try to login, register, change password or reset password the app just says "Error In Network Connection".
I am using strong internet connection, could you please advise as I have tried to on WI-FI and 4G, however it still says the same error. I am using WAMP server to connect to myphpadmin database. Please could you help and advise. I have used the internet method as well as using the doinbackground method.
Emulator , Use Device
If you use emulator. You will get this type of problem.
Use below code to check the online condition for mobile.
public boolean isNetworkOnline() {
boolean status=false;
try{
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getNetworkInfo(0);
if (netInfo != null && netInfo.getState()==NetworkInfo.State.CONNECTED) {
status= true;
}else {
netInfo = cm.getNetworkInfo(1);
if(netInfo!=null && netInfo.getState()==NetworkInfo.State.CONNECTED)
status= true;
}
}catch(Exception e){
e.printStackTrace();
return false;
}
return status;
}
Related
I try to activate WifiAP (wifi tethering) via my application code. Since there is no direct API for it, it needs to be done via reflection.
Using the approach as mentioned on StackOverflow.com.
It works fine on Nexus One, HTC Desire, Huawei Ideos (all running 2.2.x), but it doesn't run on the SGS with 2.2.1.
Checking the android.net.wifi.WifiManager class via reflection, I see that Samsung has obviously modified the class and it has 57 instead of 37 methods.
Unfortunately the modified WifiManager class is not open sourced by Samsung and the error messages don't give any details or stack trace.
I am looking for somebody who can enable WifiAP activation programmatically on the SGS, eventually by modifying the underlying system, since I'm myself am an application developer, not working on system level. Also considering contract work!
There are two things I am trying:
1) activate WifiAP directly via reflection:
Code:
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
Method[] wmMethods = wifi.getClass().getDeclaredMethods();
Log.d(TAG, "enableMobileAP methods " + wmMethods.length);
for(Method method: wmMethods){
Log.d(TAG, "enableMobileAP method.getName() " + method.getName());
if(method.getName().equals("setWifiApEnabled")) {
WifiConfiguration netConfig = new WifiConfiguration();
netConfig.SSID = "MyWifiAP";
netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
try {
Log.d(TAG, "enableMobileAP try: ");
method.invoke(wifi, netConfig, enabled);
if (netConfig.wepKeys!=null && netConfig.wepKeys.length>=1)
Log.d(TAG, "enableMobileAP key : " + netConfig.wepKeys[0]);
Log.d(TAG, "enableMobileAP enabled: ");
mIsWifiEnabled = enabled;
} catch (Exception e) {
Log.e(TAG, "enableMobileAP failed: ", e);
}
}
}
Attached are the logfiles I am getting on Nexus One (success) and SGS (failure).
The noticable part in the SGS log are maybe these lines:
Code:
D/WifiService( 2818): setWifiApEnabled: allowWifiAp: true
E/WifiService( 2818): setWifiApEnabledState 2
E/SoftapController( 2681): Softap already stopped
E/WifiService( 2818): Exception in stopAccessPoint()
E/WifiService( 2818): setWifiApEnabledState 4
D/WifiAp (23523): enableMobileAP key : null
2) another thing I try - since the modified SGS WifiManager (only that one) has a method named 'showApDialog' without any parameter taken, I try to call that method, but this also just gives an 'Error' in the log without further explanation.)
Code:
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
Method[] wmMethods = wifi.getClass().getDeclaredMethods();
Log.d(TAG, "enableMobileAP methods " + wmMethods.length);
for(Method method: wmMethods){
Log.d(TAG, "enableMobileAP method.getName() " + method.getName());
if(method.getName().equals("showApDialog")) {
WifiConfiguration netConfig = new WifiConfiguration();
try {
method.invoke(wifi);
} catch (Exception e) {
Log.e("Main", "Can't open ap dialog.", e);
}
}
}
I have been able to enable an existing configuration by passing null as the WifiConfiguration parameter to the setWifiApEnabled method.
I had the same problems as you when I tried to use this function to create a new configuration. I also failed when I tried to pass the existing configuration as a parameter, after invoking getWifiApConfiguration.
I noticed in the Android source code that there is a similar function called setWifiApConfiguration, but calling wifiManager.getClass().getMethod("setWifiApConfiguration") throws NoSuchMethodException when I run it on my SGS.
I also wondered if I can use addNetwork to create a new configuration, but suspect it is only for connecting to APs, rather than creating one.
As I only wanted to toggle the existing configuration, which I have now achieved, I stopped investigating at this point.
Hope that helps,
Good luck...
Yes, I've also got it to work meanwhile but didn't update this thread. You're right, the problem were the configuration, which had to be left empty. Cheers
thank you for sharing this, it really made my day
it seems that (on Android 2.3.4) it only works if you first disable the WiFi (Nexus One).
Hi, I have hook
Code:
findAndHookMethod(packageManagerService, null,
"installPackageWithVerificationAndEncryption", Uri.class,
"android.content.pm.IPackageInstallObserver", int.class,
String.class, "android.content.pm.VerificationParams",
"android.content.pm.ContainerEncryptionParams",
installPackageHook);
I want to create files while I am in hook.
Code:
installPackageHook = new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param)
throws Throwable {
File backupApkFile = new File(APP_DIR + File.separator + "App.apk");
backupApkFile.createNewFile();
I get EACCESS permission denied. Framework has all permissions, no?
pyler said:
I get EACCESS permission denied. Framework has all permissions, no?
Click to expand...
Click to collapse
Your code runs in the hooked process, so you only have that process' permissions.
You can try hooking the PermissionGranter class to give the hooked package additional permissions, or e.g. send a broadcast to/directly start your own activity/service to write the file (from your own app's process, without Xposed).
Currently I can get it to work if I use:
private static String address = "00:00:00:25:02:80";
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
But I want to be able to use:
Intent intent = getIntent();
newAddress = intent.getStringExtra(DeviceListActivity.EXTRA_DEVICE_ADDRESS);
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(newAddress);
So I've seen this code in other examples but It doesn't work on mine?
I have also tried other methods.
String newAddress = mBluetoothAdapter.getAddress();
This also doesn't work.
So can anybody help me with this I want to get the MAC address on it's own to connected device without declaring it.
Hello,
Check here.
Have you inserted the permission in the manifest? (android.permission.BLUETOOTH)
What does mBluetoothAdapter.getAddress() return for you?
Check also here for the remote device's MAC.
Hey, I'm fairly new to using android studios and I am trying to make an app that updates its display every few seconds.
The method I am currently using is to update when a button is pressed using the following:
public void Refreshing(View view) {
// do stuff here...
}
Where Refreshing is the onClick of a button I placed.
How can I use a similar format but instead of doing things on a button press just have it done automatically after a few seconds?
You can use a android.os.Handler for that. It allows you to interact with the event loop and post a Runnable that will be executed after a given delay
In your Activity's onCreate() method:
Code:
final int delayMs = 1000;
final Handler handler = new Handler(this);
final Runnable runnable = new Runnable() {
@Override public void run() {
// Call your refresh method
Refreshing();
// Restart the timer
handler.postDelayed(runnable, delayMs);
};
}
handler.postDelayed(runnable, delayMs);
Thanks, this is exactly what I'm looking for. I add the code to the onCreate but I had an semicolon error. So I added another semicolon but its having trouble with a few other parts. Here is what I have.
Code:
final int delayMs = 1000;
final Handler handler = new Handler([B]this[/B]);
final Runnable runnable = new Runnable() {
@Override public void run() {
// Call your refresh method
Refreshing();
// Restart the timer
handler.postDelayed([B]runnable[/B], delayMs);
};
};
handler.postDelayed(runnable, delayMs);
The error listed is:
Error : (134, 33) error: no suitable constructor found for Handler(MainActivity)
constructor Handler.Handler(Looper,Callback) is not applicable
(actual and formal argument lists differ in length)
constructor Handler.Handler(Looper) is not applicable
(actual argument MainActivity cannot be converted to Looper by method invocation conversion)
constructor Handler.Handler(Callback) is not applicable
(actual argument MainActivity cannot be converted to Callback by method invocation conversion)
constructor Handler.Handler() is not applicable
(actual and formal argument lists differ in length)
The words I bolded are underlined in red in Android Studios.
this ----------------has a constructor error
runnable ----------has a initialization error
I tried troubleshooting for a little bit and took out the this and the only error left is with runnable. It says: Error: (141, 37) error: variable runnable might not have been initialized
Yep, I wrote the code without testing it. It might need some adaptation.
Here is a version that should work:
Code:
final int delayMs = 1000;
final Handler handler = new Handler([B]this[/B]);
final Runnable runnable = new Runnable() {
@Override public void run() {
// Call your refresh method
Refreshing();
// Restart the timer
handler.postDelayed([B]this[/B], delayMs);
};
};
handler.postDelayed([B]runnable[/B], delayMs);
Thank you so much, it worked. I just had to change
Code:
final Handler handler = new Handler(this);
to
Code:
final Handler handler = new Handler();
First of all, we need to reboot the device by button click.
Device: Mediatek MT6737M Android 6.0 running Marshmallow
I currently have three devices. One rooted with Magisk another SuperSU the third with Kingroot. In the settings on all three root managers I have it set to grant all permissions. When we try and restart Kingroot flashes a prompt to allow permission which we can work around but Kingroot is riddled with garbage that we don't want. We want to use Magisk or SuperSU because they are clean with less baggage. Magisk and SuperSU however throw an error: java.io.IOException:
Code:
Error running exec(). Command: [/system/bin/su, -c, reboot now] Working Directory: null Environment: null.
This is the code we're using to access PowerManager:
Code:
void reboot() {
if (reboot) {
try {
Process proc = Runtime.getRuntime().exec(new String[]{"/system/bin/su", "-c", "reboot"});
proc.waitFor();
} catch (Exception ex) {
Log.e(TAG, "Error ", ex);
}
}
}
Is there a way to grant permission to this process using either Magisk or SuperSU? If not is there another rooting management tool or software that is clean and malware free that can achieve that?
NOTE: Code by senior developer I am a Baby, Jr dev here tasked with finding the answer. Please be patient if I ask dumb questions.
Ok so first thing I'll start by saying that you should be making su calls in a background thread. The su call is a blocking call so it will block the UI thread which can cause ANRs (crashes) and overall bad user experience. AsyncTask is perfect for su calls to run in the background instead.
You should also stick with Magisk as it is actively being developed and is the current standard.
Let's get started. Create a new class and call it RootShell.java. Then copy the following code into it.
Java:
class RootShell {
private static void exec(String[] cmd) {
new Execute().execute(cmd);
}
private static class Execute extends AsyncTask<String, Void, Void> {
Override
protected Void doInBackground(String... cmds) {
try {
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
for (String tmpCmd : cmds) {
os.writeBytes(tmpCmd + "\n");
}
os.writeBytes("exit\n");
os.flush();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
}
Keep in mind that XDA has awful code formatting so the Override should have the @ symbol in front of it.
Now you can pass single or multiple root commands to this class which will be executed in a background thread. Here's how...
Lets say you're using a button in another class to reboot the phone. This is what it would look like...
Java:
private void rebootButton(View view) {
String[] cmd = { "reboot" };
RootShell.exec(cmd);
}
To pass multiple commands your button would look like this.
This is to reboot into safe mode...
Java:
private void rebootSafeMode(View view) {
String[] cmd = {
"setprop persist.sys.safemode 1",
"setprop ctl.restart zygote"
};
RootShell.exec(cmd);
}
For more info on how to properly su you should check out the following link...
https://su.chainfire.eu/
Hope this helps you with your app and good luck.