FTPClient cannot resolve host even with internet permission - java

I've added the correct permission into my AndroidManifest.XML file to enable me connect to the internet from my app
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.my_test_app">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".LogOn"></activity>
<activity android:name=".ftpDetails"/>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
But, when trying to establish an FTP connection like so
FTPClient FtpClient = new FTPClient();
FtpClient.connect(ftpServer + ftpFolder); // THIS IS WHERE THE ERROR OCCURS
FtpClient.login(ftpUser, ftpPass);
int reply = FtpClient.getReplyCode();
The error occurs on FtpClient.connect(ftpServer + ftpFolder);
The values in the variables are in the format of
ftpServer = ftp://ftp.myServer.co.uk/mySite.co.uk/
ftpFolder = My Folder (Test)
I can get to this folder through Windows File Explorer on my PC so I know it's a valid path, but when testing in the app I get the following error
Unable to resolve host "ftp://ftp.myServer.co.uk/mySite.co.uk/My Folder": No address associated with hostname

The argument of FTPClient.connect method (or actually the inherited SocketClient.connect) is hostname, not URL.
So it should be:
ftpServer = "ftp.myServer.co.uk";

Related

Using O Auth for google api on android app

What should i add here for the scheme for URl redirect, can i add anything, like "com.example.oauth/:oauth2redirect"(Package name:/ oauth2redirect)?.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.oauth">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.INTERNET">
</uses-permission>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.Oauth">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<data android:scheme=" ">
</data>
</intent-filter>
The most common option when learning Mobile OAuth is to start with a value like this, using a reverse DNS style of naming, to include your company + app names:
com.mycompany.myapp:/callback
A good starting point for something to compare against is the Android AppAuth Code Sample, where you just specify a scheme value in the gradle file.
If it helps, my Blog Post has some step by step instructions to get the sample running.

Java: Android App works on virtual device but crashes on real one

I'm working on fall detection app. I was testing it on virtual devices API: 23,28,29 and app works fine but when I run this app on my phones with Android 6 and 9 it crash
immediately.
What are the solutions ?
Thanks in Advance.
Run desription
I checked MainActivity line from errors window but i have no suggestion what I can do.
MainActivity line175
Logcat errors after open app: Logcat
My manifest
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_falling_down_stairs"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<receiver android:name=".MyLocationService"/>
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version"/>
<activity android:name=".CaretakersList"></activity>
<activity android:name=".settingContact" />
<service
android:name=".AlertService"
android:enabled="true"
android:exported="true" />
<activity android:name=".MainActivity" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This is because DecimalFormat generate localized string, and the decimal separator can be different in some locale.
You can force the good locale like this :
DecimalFormat precision = new DecimalFormat("0.00", new DecimalFormatSymbols(Locale.US));
More info here
From your stacktrace there is error in Real number format in method of your MainACtivity onSensorChanged with value "9,35". In java all floating numbers use dot like this "9.35". Check this method and use correct format of Real number

Flurry integration Android throwing errors

I'm trying to integrate flurry into my android app. I'm using the recommended setting and have repositories{jcenter()} and
// Required for Flurry Analytics integration
compile 'com.flurry.android:analytics:8.2.0#aar'
// Optional - If you want to use the Ads SDK
compile 'com.flurry.android:ads:8.2.0#aar'
in the gradle as the docs suggest. I keep getting errors in the that Application is not resolved. The docs really blow and I'm not 100% sure what going on. I've never integrated flurry before can someone please help! I put the manifest and the class i'm using below. I know it doesn't have a key I'm still working on removing errors. I'm dumping the that class in the main file for simplicity for now.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tempconversion.october.com.myapplication">
<!-- Required permissions - Internet access -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- Highly Recommended permission - External memory pre-caching -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- Optional permission - Location based ad targeting -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="F to C and K"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
class in main file
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
new FlurryAgent.Builder()
.withLogEnabled(true)
.withCaptureUncaughtExceptions(true)
.withContinueSessionMillis(10)
.withLogLevel(VERBOSE)
.build(this, FLURRY_API_KEY);
}
}
Declare the application name in manifest.xml file.
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="F to C and K"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

Registration Error :null in android

I have been implementing the code of login and registration app from http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/
I copy pasted the code along with following the instructions but I am still getting the registration error : null in the log cat on pressing the register button.
The php files(ex: register.php) are displaying {"error":true,"error_msg":"Required parameters (name, email or password) is missing!"} , that means they are working fine.
I am using xampp and have kept the files in htdocs. I have checked various url in Appconfig.java such as 127.0.0.1, 10.0.2.2:8080, 10.0.2.2:80, and the ip of my computer system from ipconfig cmd, but still getting same error.
Here is the code of Appconfig.java.
package com.urjapawar.hackathon1;
public class AppConfig {
// Server user login url
public static String URL_LOGIN ="http://192.168.2.5/android_login_api/login.php";
// Server user register url
public static String URL_REGISTER = "http://192.168.2.5/android_login_api/register.php";
}
and here is the code of Android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.urjapawar.hackathon1" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="com.urjapawar.hackathon1.AppController"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity
android:name=".LoginActivity"
android:label="#string/app_name"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustPan" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:launchMode="singleTop" />
<activity
android:name=".RegisterActivity"
android:label="#string/title_activity_register"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustPan" >
</activity>
</application>
Also I have checked correctly username and password in config.php, Please help.
I just need to replace 192.168.2.5 with 192.168.2.5:80

Android AWS Security Credential Issue

I am having a problem integrating the AmazonS3PersonalFileStore demo app login into my App
I have set up my TVM and everything works fine on the demo app, it also runs correctly when I copy/paste the project and rename it.
The issue comes when I begin pasting my .javas from my main app into the pasted Demo app, now when I login, I get the error
Credential Problem!
AWS Credentials not configured correctly. Please review the README file.
the readme refers to project setup and the .properties file, all of which I did not touch
Here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.amazonaws.demo.personalfilestore"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".S3PersonalFileStore"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Login"></activity>
<activity android:name=".s3.S3BucketView"></activity>
<activity android:name=".s3.S3ObjectView"></activity>
<activity android:name=".s3.S3AddObjectView"></activity>
<activity
android:screenOrientation="portrait"
android:name="com.example.indrive.MainMenu"
android:label="#string/main_menu" />
<activity
android:screenOrientation="portrait"
android:name="com.example.indrive.TripMain"
android:label="#string/trips"/>
<activity
android:screenOrientation="portrait"
android:name="com.example.indrive.TripView"
android:label="#string/trip_view"/>
<activity
android:screenOrientation="portrait"
android:name="com.example.indrive.DiagnosticsMain"
android:label="#string/diagnostics"/>
<activity
android:screenOrientation="portrait"
android:name="com.example.indrive.DtcListView"
android:label="#string/dtcs"/>
<activity
android:screenOrientation="portrait"
android:name="com.example.indrive.RpmComparison"
android:label="#string/rpm_distribution"/>
<activity
android:screenOrientation="portrait"
android:name="com.example.indrive.UbiMain"
android:label="#string/ubi"/>
<activity
android:screenOrientation="portrait"
android:name="com.example.indrive.UbiView"
android:label="#string/ubi_view"/>
<activity
android:screenOrientation="portrait"
android:name="com.example.indrive.UsageMain"
android:label="#string/usage"/>
<activity
android:screenOrientation="portrait"
android:name="com.example.indrive.EnvironmentalMain"
android:label="#string/environmental_main"/>
<activity
android:screenOrientation="portrait"
android:name="com.example.indrive.ComparisonMain"
android:label="#string/vehicle_comparison"/>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxxxxx"/>
</application>
</manifest>
Although I have added new code, I am pretty sure that none of it is running, since none of my activities are being created
Update: I tried adding an EC2 role to the TVM Elastic Beanstalk with the same permissions as the IAM TVMUser, but the demo app wouldn't even work
Update 2: Tried a bunch of different IAM configurations for the TVM IAM User / Elastic Beanstalk, nothing worked
I had the same issue when integrating the AmazonS3PersonalFileStore demo app login into my app.
The problem was that the request to the TVM via the HTTP request was blocked. This is due to the android sdk's StrictMode.ThreadPolicy which does not allow network operations to execute on the UI thread.
This restriction can be changed, using:
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
Add the above code into your main activity's onCreate() method.
In addition, it is always recommended to move network operation off the UI thread, for example, using AsyncTask.
I am confident this will fix your problem.

Categories

Resources