[Q] FTP via app - Android Software Development

I am developing an app that I need to make download something off an ftp server. I have no idea how to do this. I tried to using EdtFTPj but its giving me an exception: 02-10 16:36:43.989: WARN/System.err(456):java.net.UnknownHostException: ftp.newlyme.net
The host I use in filezilla is the same one im using for this and it works just fine in filezilla. Any ideas.
CODE:
Code:
private String host = "ftp.newlyme.net";
private String password = "*****";
private String username = "*******";
private int port = 21;
Code:
FileTransferClient ftp = new FileTransferClient();
try {
ftp.setRemoteHost(host);
ftp.setRemotePort(port);
ftp.setUserName(username);
ftp.setPassword(password);
ftp.connect();
} catch (FTPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
obviously I have the password and username filled in correctly but I dont need everyone seeing that info !
Help??

maybe host should have ftp://ftp.name.com?
Sent from my SGH-I897 using XDA App

sardeenz said:
maybe host should have ftp://ftp.name.com?
Sent from my SGH-I897 using XDA App
Click to expand...
Click to collapse
Tried that too. Didn't work.

Related

Xda Zinc ~~ Help me !

Hopefully this is the right forum.
Ok I am creating a simple application for Xda Zinc PDA from O2. However when I implement DiscoveryListener and use FileConnection my application crashes. So I did some checking with this code :
Code:
Object obj = null,obj2=null;
try{
obj = Class.forName("javax.microedition.lcdui.TextField");
obj2 = Class.forName("javax.bluetooth.DiscoveryListener");
}catch (ClassNotFoundException e){
e.printStackTrace();
}
Alert alert = new Alert("Testing:", obj.toString()+obj2.toString() + " available", null, null);
alert.setType(AlertType.CONFIRMATION);
alert.setTimeout(5000);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
display.setCurrent(alert);
I also tried with System.getProperty("full package name"); even it doesnt crash but it says "null null available". If I take out the DiscoveryListener and FileConnection the GUI appears and it works fine. So I wonder why ?? I am pretty sure that the PDA support bluetooth. I just need help to get it working.
Thanks.

[Q] Saving drawables to SD

hello again. does anyone here know the proper way to save images (drawable resources) displayed in an app to the sd card/gallery? ive found two different methods that have given me the same result of saving an image of very degraded quality (tried using both JPG and PNG compression).
here is the code i currently have hacked together:
Code:
String imagename = modelname.toLowerCase() + "_photo_" + imagenum;
Log.i(DEBUG_TAG,"image : " + modelname.toLowerCase() + "_photo_" + imagenum);
int resID = getResources().getIdentifier(imageName,"drawable",packageName);
Log.i(DEBUG_TAG,"resID : " + resID);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), resID);
File SpicyDirectory = new File("/sdcard/Images/");
SpicyDirectory.mkdirs();
String filename="/sdcard/Images/" + imagename + ".jpg";
FileOutputStream out = null;
try {
out = new FileOutputStream(filename);
bmp.compress(Bitmap.CompressFormat.JPG, 100, out);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
out=null;
}
someone save my a$$ plz
ty
bamp
dont let me put a crappy app out there

[Q] java and xml

something is wrong with my setup...
Eclipse Keplar
Windows 7 32bit
java 7u51
db = dbf.newDocumentBuilder(); throws ParserConfigurationError..
please help me. this file is as simple as i could make it.
import java.io.File;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
public class XMLHELP {
public static void main(String[] args) {
File file = new File("foo.xml");
DocumentBuilderFactory dbf;
DocumentBuilder db = null;
dbf = DocumentBuilderFactory.newInstance();
try {
db = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
Document doc = db.parse(file);
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
ParserConfigurationError means that you misconfigured your factory.
Look here at the newInstance() method in the DocumentBuilderFactory API.
That tells you where it looks for configurations if you don't supply any. One of those files may be messed up or out of place, so give it your own configuration. I just ran the exact same code with a dummy XML file and it worked perfectly with no exceptions or errors. Look up how to configure it yourself or what the default should be, and that could fix your problem.

[Q] Help with App permission search application

Hello,
I am student in my final year doing a project based on android development. I am thinking of creating an application that scans all the installed application in the device and recover all the list of permission associated with the app.. I will then manually use the data to check the manifest files manually, so that I can flag up any app that has more permission than it should.
I am learning and just starting creating it in eclipse. But, any advice would greatly be appreciated as am new to this development world.
I am thinking of creating a GUI for the layout but how can I make it list all the installed application on the device before I can proceed into getting the permission.
Thank you.
You need to use the PackageManager
The solution is on stackoverflow (love that site), but since I can't post links yet, I'll simply give you the code (should work):
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0);
for (Object obj : pkgAppsList) {
ResolveInfo resolveInfo = (ResolveInfo) obj;
PackageInfo packageInfo = null;
try {
packageInfo = getPackageManager().getPackageInfo(resolveInfo.activityInfo.packageName, PackageManager.GET_PERMISSIONS);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] requestedPermissions = packageInfo.requestedPermissions;
}
Good luck!!
Edwin Bos said:
You need to use the PackageManager
The solution is on stackoverflow (love that site), but since I can't post links yet, I'll simply give you the code (should work):
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0);
for (Object obj : pkgAppsList) {
ResolveInfo resolveInfo = (ResolveInfo) obj;
PackageInfo packageInfo = null;
try {
packageInfo = getPackageManager().getPackageInfo(resolveInfo.activityInfo.packageName, PackageManager.GET_PERMISSIONS);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] requestedPermissions = packageInfo.requestedPermissions;
}
Good luck!!
Click to expand...
Click to collapse
Is it possible I can create it within a searchView so that it can search it and display the installed application. But, displayed the app in a scroll view as well.

[Q] Google Drive android api - Downloading sqlite db file from drive

I am using the below code for downloading an already uploaded sqlite db file from google drive to the data/data/packagename/databases folder, but when the method completes, I am seeing a db corruption warning message logged in logcat and also all the data on the device for the app is overwritten and shows up blank, upon opening the app.
Code:
mfile = Drive.DriveApi.getFile(mGoogleApiClient, mResultsAdapter.getItem(0).getDriveId());
mfile.openContents(mGoogleApiClient, DriveFile.MODE_READ_ONLY, null).setResultCallback(contentsOpenedCallback);
--mfile is an instance of DriveFile
final private ResultCallback<ContentsResult> contentsOpenedCallback = new ResultCallback<ContentsResult>()
{
@Override
public void onResult(ContentsResult result)
{
if (!result.getStatus().isSuccess())
{
FileUtils.appendLog(getApplicationContext(), Tag + "-onResult", "Error opening file");
return;
}
try
{
if (GetFileFromDrive(result))
{
//FileUtils.Restore(getApplicationContext());
SharedPrefHelper.EditSharedPreference(getApplicationContext(), Constants.PREFS_DO_RESTORE, false);
}
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
private boolean GetFileFromDrive(ContentsResult result)
{
Contents contents = result.getContents();
//InputStreamReader rda = new InputStreamReader(contents.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(contents.getInputStream()));
FileOutputStream outStream;
String currLine;
boolean restoreSuccess = false;
File sourceDbFile = BackupDBBeforeDeletion();
if(sourceDbFile != null)
sourceDbFile.delete();
try
{
outStream = new FileOutputStream(getApplicationContext().getDatabasePath(Constants.DB_NAME));
while ((currLine = reader.readLine()) != null)
{
outStream.write(currLine.getBytes());
}
outStream.flush();
reader.close();
outStream.close();
restoreSuccess = true;
}
catch (FileNotFoundException e)
{
// TODO: Log exception
}
catch (IOException e)
{
// TODO: Log Exception
}
return restoreSuccess;
}
When the method GetFileFromDrive completes, a db corruption shows up on LogCat and all the existing data on the app's datanase file (sqlite db) is gone.
Please help, as I have verified that the drive uploaded sqlite db file is correct and well formed, by downloading the same and opening it up in Sqlite Browser. It's the download from drive that is not working.

Categories

Resources