| Author |
Message |
Shibbs Freshman

Joined: 05 Sep 2008 Posts: 2
|
Posted: Fri Sep 05, 2008 3:25 pm Post subject: Size of SD Card? |
|
|
Hi +-,
Can we determine the size of the emmualted sdCard though our Java File API's.
i know its supported in 1.6 like
file.getTotalSpace()
file.getFreeSpace() etc....
but i can't get Android compile your FileBrowser files using java 1.6 sdk.
it just don't recognize file.getTotalSpace() api.
Your code runs well for java 1.5 & 1.6, but it shows compile errors the moment i keep any java 1.6 specific api's.
I have updated the project settings & Windows / Preferences of Eclipse so that it uses the java 1.6 sdk.
Even the JAVA_HOME & PATH System variables are updated to point to java 1.6 sdk.
and java -version & javac -version returns 1.6.
Does Android support's java 1.6 at all or not ?
Is there any way we could find the total space available in SD Card through code?
Your help is much appreciated.
Thanks,
Shibbs |
|
| Back to top |
|
 |
cgreen Experienced Developer


Joined: 16 Jul 2008 Posts: 56
|
Posted: Fri Sep 05, 2008 4:26 pm Post subject: |
|
|
android uses its own runtime, so youre on the wrong track using jre 1.6
the android runtime won't work with any imported jre packages, so you'll have to check the android specific packages to solve you problem. _________________ localhost is the android emulator |
|
| Back to top |
|
 |
Shibbs Freshman

Joined: 05 Sep 2008 Posts: 2
|
Posted: Fri Sep 05, 2008 6:48 pm Post subject: |
|
|
Actually i am talking about that java only which Android support.
Android has support for Java API's and the FileBrowser we have in place uses Java File Api's to a large extent.
However by the Java api's present in Android we can't get the size of a directory like sdcard or can we?
If yes, can someone guide me in how to do it?
i hope now the intent is clear.
Thanks,
Shibbs |
|
| Back to top |
|
 |
Anm Freshman

Joined: 15 Oct 2008 Posts: 7
|
Posted: Wed Oct 15, 2008 8:28 am Post subject: |
|
|
Love examples like this. Thanks a bunch.
Updated code for 1.0
| Java: |
package org.anddev.android.filebrowser;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.anddev.android.filebrowser.iconifiedlist.IconifiedText;
import org.anddev.android.filebrowser.iconifiedlist.IconifiedTextListAdapter;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
public class AndroidFileBrowser extends ListActivity {
private enum DISPLAYMODE {
ABSOLUTE, RELATIVE;
}
private final DISPLAYMODE displayMode = DISPLAYMODE.RELATIVE;
private List<IconifiedText> directoryEntries = new ArrayList<IconifiedText>();
private File currentDirectory = new File( "/" );
/** Called when the activity is first created. */
@Override
public void onCreate( Bundle icicle ) {
super.onCreate( icicle );
browseToRoot();
}
/**
* This function browses to the root-directory of the file-system.
*/
private void browseToRoot() {
browseTo( new File( "/" ) );
}
/**
* This function browses up one level according to the field:
* currentDirectory
*/
private void upOneLevel() {
if( this.currentDirectory.getParent() != null )
this.browseTo( this.currentDirectory.getParentFile() );
}
private void browseTo( final File aDirectory ) {
// On relative we display the full path in the title.
if( this.displayMode == DISPLAYMODE.RELATIVE )
this.setTitle( aDirectory.getAbsolutePath() + " :: "
+ getString( R.string.app_name ) );
if( aDirectory.isDirectory() ) {
this.currentDirectory = aDirectory;
fill( aDirectory.listFiles() );
} else {
OnClickListener okButtonListener = new OnClickListener() {
// @Override
public void onClick( DialogInterface arg0, int arg1 ) {
// Lets start an intent to View the file, that was
// clicked...
AndroidFileBrowser.this.openFile( aDirectory );
}
};
OnClickListener cancelButtonListener = new OnClickListener() {
// @Override
public void onClick( DialogInterface arg0, int arg1 ) {
// Do nothing ^^
}
};
createFileOpenDialog(
"Question", R.drawable.folder,
"Do you want to open that file?\n" + aDirectory.getName(),
"OK", okButtonListener, "Cancel", cancelButtonListener
).show();
}
}
private AlertDialog createFileOpenDialog(
String title, int icon_res, String message,
String positive_text, OnClickListener positive_listener,
String negative_text, OnClickListener negative_listener
)
{
// TODO: Create adb at initialization so we don't have to go through this every time
AlertDialog.Builder adb = new AlertDialog.Builder( this );
adb.setTitle( title );
adb.setIcon( icon_res );
adb.setMessage( message );
adb.setPositiveButton( positive_text, positive_listener );
adb.setNegativeButton( negative_text, negative_listener );
return adb.create();
}
private void openFile( File aFile ) {
Intent myIntent =
new Intent(
android.content.Intent.ACTION_VIEW,
Uri.parse( "file://" + aFile.getAbsolutePath() )
);
startActivity( myIntent );
}
private void fill( File[] files ) {
this.directoryEntries.clear();
// Add the "." == "current directory"
this.directoryEntries.add( new IconifiedText(
getString( R.string.current_dir ), getResources().getDrawable(
R.drawable.folder ) ) );
// and the ".." == 'Up one level'
if( this.currentDirectory.getParent() != null )
this.directoryEntries.add( new IconifiedText(
getString( R.string.up_one_level ), getResources()
.getDrawable( R.drawable.uponelevel ) ) );
Drawable currentIcon = null;
for( File currentFile : files ) {
if( currentFile.isDirectory() ) {
currentIcon = getResources().getDrawable( R.drawable.folder );
} else {
String fileName = currentFile.getName();
/*
* Determine the Icon to be used, depending on the FileEndings
* defined in: res/values/fileendings.xml.
*/
if( checkEndsWithInStringArray( fileName, getResources()
.getStringArray( R.array.fileEndingImage ) ) ) {
currentIcon = getResources().getDrawable( R.drawable.image );
} else if( checkEndsWithInStringArray( fileName, getResources()
.getStringArray( R.array.fileEndingWebText ) ) ) {
currentIcon = getResources().getDrawable(
R.drawable.webtext );
} else if( checkEndsWithInStringArray( fileName, getResources()
.getStringArray( R.array.fileEndingPackage ) ) ) {
currentIcon = getResources()
.getDrawable( R.drawable.packed );
} else if( checkEndsWithInStringArray( fileName, getResources()
.getStringArray( R.array.fileEndingAudio ) ) ) {
currentIcon = getResources().getDrawable( R.drawable.audio );
} else {
currentIcon = getResources().getDrawable( R.drawable.text );
}
}
switch( this.displayMode ) {
case ABSOLUTE:
/* On absolute Mode, we show the full path */
this.directoryEntries.add( new IconifiedText( currentFile
.getPath(), currentIcon ) );
break;
case RELATIVE:
/*
* On relative Mode, we have to cut the current-path at the
* beginning
*/
int currentPathStringLength = this.currentDirectory
.getAbsolutePath().length();
this.directoryEntries.add( new IconifiedText( currentFile
.getAbsolutePath().substring(
currentPathStringLength ), currentIcon ) );
break;
}
}
Collections.sort( this.directoryEntries );
IconifiedTextListAdapter itla = new IconifiedTextListAdapter( this );
itla.setListItems( this.directoryEntries );
this.setListAdapter( itla );
}
@Override
protected void onListItemClick( ListView l, View v, int position, long id ) {
super.onListItemClick( l, v, position, id );
String selectedFileString = this.directoryEntries.get( position )
.getText();
if( selectedFileString.equals( getString( R.string.current_dir ) ) ) {
// Refresh
this.browseTo( this.currentDirectory );
} else if( selectedFileString
.equals( getString( R.string.up_one_level ) ) ) {
this.upOneLevel();
} else {
File clickedFile = null;
switch( this.displayMode ) {
case RELATIVE:
clickedFile = new File( this.currentDirectory
.getAbsolutePath()
+ this.directoryEntries.get( position ).getText() );
break;
case ABSOLUTE:
clickedFile = new File( this.directoryEntries
.get( position ).getText() );
break;
}
if( clickedFile != null )
this.browseTo( clickedFile );
}
}
/**
* Checks whether checkItsEnd ends with one of the Strings from fileEndings
*/
private boolean checkEndsWithInStringArray( String checkItsEnd,
String[] fileEndings ) {
for( String aEnd : fileEndings ) {
if( checkItsEnd.endsWith( aEnd ) )
return true;
}
return false;
}
}
|
|
|
| Back to top |
|
 |
fabricapo Once Poster

Joined: 23 Oct 2008 Posts: 1
|
Posted: Thu Oct 23, 2008 5:17 am Post subject: .apk for Android 1.0 (G1) |
|
|
Any chance you can post an .apk for the G1 somewhere? It is a much needed apps...
fabrizio |
|
| Back to top |
|
 |
miserlou Once Poster


Joined: 29 Oct 2008 Posts: 1
|
Posted: Wed Oct 29, 2008 12:26 am Post subject: |
|
|
Daaamn, this is handy! Came here looking for a good file open dialog, this is wonderful. Just what I need.
I'm going to be releasing my app under the GNU-GPL, can I consider your code to be public domain? |
|
| Back to top |
|
 |
ravi Freshman

Joined: 04 Nov 2008 Posts: 3
|
Posted: Sun Nov 16, 2008 10:13 pm Post subject: |
|
|
Hi Nicholas,
I'm trying to install the apk into /system/app using adb, but am unable to do so (getting a 'read-only file system' message). Are there any specific sequence of steps to install the apk in the above folder for administrative privileges? I'm a beginner and this may be a basic question (thank you for your patience).
Thanks,
Ravi
| plusminus wrote: | Hello cabernet1976,
the reason you cannot browse to that folder is because you need Administrator-Privileges, which you do not have with your app.
I've heard, that if you install the apk into /system/app then it will run at a higher level.
Regards,
plusminus |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
© 2007, Android Development Community
All rights reserved.
Powered by phpBB.
|