Domanda

I'm trying to test my app, but having no luck with any emulators. I've tried a few different AVD's and BlueStacks. Due to the way they mount a virtual SDCard, my app is not finding a cache directory as expected. However, when I run the same app on two different Android phones, it seems to work properly. Facing this problem made me think there must be a better way of referencing the folder I'm looking for.

I'm using this in my onCreate:

    // Check if application exists
    for (int i = 0; i < list.size(); i++) {
        if (list.get(i).packageName.equals("com.someapphere")) {
            v.setText("Application Found");
            break;
        } else {
            v.setText("Application Not Found");
        }
    }

    if (v.getText() == "Application Found") {
        // Check for Cache Usage
        final File dataStore = Environment.getExternalStorageDirectory();
        try {
            File tCache = new File(dataStore.getAbsolutePath()
                 + "/Android/data/com.someapphere/cache");
            long tCacheSize = folderSize(tCache);

            if (tCacheSize == 0) {
                 v2.setText(" Nothing to do");
            } else {
              // Start Async task - delete files
              ...
            }
        } catch(Exception e) {
              v2.setText(" Cache not found");
        }
    }

I took out some of the other irrelevant stuff I'm doing here, but the rest should replicate the issue. If it's not already obvious, I'm still quite new to programming.

È stato utile?

Soluzione

Text can't be compared as '=='.

You should try like this:

v.getText().toString().equalsIgnoreCase("Application Found");

and its not working in emulator may be because you don't have SD card support in emulator.

In Eclipse go in menu Window – Android SDK and Avg Manager Select Virtual devices Select AVD Name where you need install SD card Click on Edit button In open dialog go to SD card – Size: and write 500 Press button Edit AVD Run AVD emulator

Hope it Helps!!

Altri suggerimenti

One possible bug:

v.getText() == "Application Found" // try .equals instead

Try to replace this code :

File tCache = new File(dataStore.getAbsolutePath() + "/Android/data/com.someapphere/cache");

With this code :

File cache_Folder = new File(dataStore + "/Android/data/com.someapphere/cache");
if (!cache_Folder.exists())
    cache_Folder.mkdirs();

File tCache = new File(dataStore + "/Android/data/com.someapphere/cache");
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top