10-15-2012 12:37 PM
Post code and I'll tell you what I see.
10-15-2012 01:16 PM - edited 10-15-2012 01:17 PM
Thanks mreed. I have no code that I can post anymore... been tryingto modify your demo code to get my functionality to work. Tried everything I can think of. Used timer to wait for x num seconds on powerup when no card detected, not working right.
Or what will happen is a screen will display showing no card, then over top of it the screen will show that there is a card (after powerup)
10-15-2012 01:50 PM
Would it be best to put a timer in you isSDCardPresent() function?
10-15-2012 02:59 PM
Post code and I'll tell you what I see. I'm not going to write anything new... as you should already have everything you need in this thread.
10-15-2012 04:43 PM
Here is what I thgought would solve the issue. TimerTask waiting for 10 seconds if sd card not found. Then screen based on result.
package mypackage;
import java.util.Enumeration;
import java.util.Timer;
import java.util.TimerTask;
import javax.microedition.io.file.FileSystemListener;
import javax.microedition.io.file.FileSystemRegistry;
import net.rim.device.api.system.ApplicationManager;
import net.rim.device.api.system.SystemListener2;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
public class MyApp extends UiApplication implements SystemListener2, FileSystemListener {
private MainScreen mainScreen;
public static void main( String[] args ) {
final MyApp theApp = new MyApp();
theApp.invokeLater( new Runnable() {
public void run() {
theApp.bootloader();
}
} );
theApp.enterEventDispatcher();
}
private void bootloader() {
mainScreen = new MainScreen();
ApplicationManager applicationManager = ApplicationManager.getApplicationManager();
boolean inStartup = applicationManager.inStartup();
mainScreen.add( new LabelField( "inStartup[" + inStartup + "]" ) );
if ( !inStartup ) {
mainScreen.add( new LabelField( "SDCard[" + isSDCardPresent() + "]" ) );
mainScreen.add( new LabelField( "App launch complete" ) );
}
else {
addSystemListener( this );
FileSystemRegistry.addFileSystemListener( this );
}
if (isSDCardPresent()) {
pushScreen( mainScreen );
}
else {
Timer t = new Timer();
TimerTask tt = new TimerTask()
{
public void run() {
if (isSDCardPresent()) {
pushScreen( mainScreen );
}
else {
pushScreen(new NoCardScreen());
}
}
};
t.schedule(tt, 10000);
}
}
private boolean isSDCardPresent() {
Enumeration roots = FileSystemRegistry.listRoots();
while (roots.hasMoreElements()) {
String root = (String) roots.nextElement();
if ( root.equals( "SDCard/" ) ) {
return true;
}
}
return false;
}
public void powerUp() {
removeSystemListener( this );
synchronized (UiApplication.getEventLock()) {
mainScreen.add( new LabelField( "Power up complete. SDCard[" + isSDCardPresent() + "]" ) );
mainScreen.add( new LabelField( "SystemListener2 removed" ) );
}
}
public void rootChanged( int state, String rootName ) {
boolean sdCardPresent = isSDCardPresent();
if ( sdCardPresent ) {
FileSystemRegistry.removeFileSystemListener( this );
}
synchronized (UiApplication.getEventLock()) {
mainScreen.add( new LabelField( "Root changed. SDCard[" + sdCardPresent + "]" ) );
if ( sdCardPresent ) {
mainScreen.add( new LabelField( "FileSystemListener removed" ) );
}
}
}
public void usbConnectionStateChange( int state ) { }
public void batteryGood() { }
public void batteryLow() { }
public void batteryStatusChange( int status ) { }
public void powerOff() { }
public void backlightStateChange( boolean on ) { }
public void cradleMismatch( boolean mismatch ) { }
public void fastReset() { }
public void powerOffRequested( int reason ) { }
}
This does not work, just hangs.
10-15-2012 04:53 PM
Changed timer code to
Timer t = new Timer();
TimerTask tt = new TimerTask()
{
public void run() {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
if (isSDCardPresent()) {
pushScreen( mainScreen );
}
else {
pushScreen(new NoCardScreen());
}
}
} );
}
};
t.schedule(tt, 10000);Now app runs after device restart but only shows no ad card screen. Like it didnt detect card in time maybe?
10-15-2012 05:07 PM
Should this not just work? Look for sdcard, if not found wait for some seconds then try again. If not found push nosdcard screen, otherwise push mainscreen.,
package mypackage;
import java.util.Enumeration;
import java.util.Timer;
import java.util.TimerTask;
import javax.microedition.io.file.FileSystemRegistry;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
public class MyApp extends UiApplication {
private MainScreen mainScreen;
public static void main( String[] args ) {
final MyApp theApp = new MyApp();
theApp.invokeLater( new Runnable() {
public void run() {
theApp.bootloader();
}
} );
theApp.enterEventDispatcher();
}
private void bootloader() {
mainScreen = new MainScreen();
mainScreen.add( new LabelField( "mainscreen" ) );
if (isSDCardPresent()) {
pushScreen( mainScreen );
}
else {
Timer t = new Timer();
TimerTask tt = new TimerTask()
{
public void run() {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
if (isSDCardPresent()) {
pushScreen( mainScreen );
}
else {
pushScreen(new NoCardScreen());
}
}
} );
}
};
t.schedule(tt, 20000);
}
}
private boolean isSDCardPresent() {
Enumeration roots = FileSystemRegistry.listRoots();
while (roots.hasMoreElements()) {
String root = (String) roots.nextElement();
if ( root.equals( "SDCard/" ) ) {
return true;
}
}
return false;
}
}
10-15-2012 07:23 PM
This is going to be my last post on this thread, then I'm unsubscribing because you're not listening. In a previous reply I said:
I would use a TimerTask in powerUp() rather than sleep. From my previous test it was about 10 seconds after powerUp() before it mounted.
10 seconds after powerUp(), not 10 seconds after the app auto-starts. And it was just 10 seconds that one time I happened to count, its not a hard number.
10-15-2012 07:29 PM
Thank mreed. Sorry, Not sure what you mean. Which sleep?
10-15-2012 08:23 PM
Sorry mreed. Just trying to get this figured out and havng difficult time. Tried a lot of things and cant get it going. I got that youre trying and I'm, not seeming to figure this out. Sorry, please unsubscribe, forget this thread. I appreciate your help though, really do. I know you have a much better understanding of how this should work. Thanks for all of your assistance, very much appreciated it.