Workaround strange getExternalFilesDir freeze
This commit is contained in:
parent
aa3af3bf67
commit
2b0a4f552b
1 changed files with 43 additions and 9 deletions
|
@ -24,6 +24,7 @@ import android.preference.*;
|
||||||
public class FWGSLib
|
public class FWGSLib
|
||||||
{
|
{
|
||||||
private static final String TAG = "FWGSLib";
|
private static final String TAG = "FWGSLib";
|
||||||
|
static String externalFilesDir;
|
||||||
public static boolean FBitSet( final int bits, final int mask )
|
public static boolean FBitSet( final int bits, final int mask )
|
||||||
{
|
{
|
||||||
return ((bits & mask) == mask);
|
return ((bits & mask) == mask);
|
||||||
|
@ -110,19 +111,52 @@ public class FWGSLib
|
||||||
return dir.getPath() + "/xash";
|
return dir.getPath() + "/xash";
|
||||||
return "/sdcard/xash";
|
return "/sdcard/xash";
|
||||||
}
|
}
|
||||||
|
static class GetExternalFilesDir extends Thread
|
||||||
|
{
|
||||||
|
Context ctx;
|
||||||
|
GetExternalFilesDir( Context ctx1 )
|
||||||
|
{
|
||||||
|
ctx = ctx1;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File f = ctx.getExternalFilesDir(null);
|
||||||
|
|
||||||
|
f.mkdirs();
|
||||||
|
|
||||||
|
externalFilesDir = f.getAbsolutePath();
|
||||||
|
Log.d(TAG, "getExternalFilesDir success");
|
||||||
|
}
|
||||||
|
catch( Exception e )
|
||||||
|
{
|
||||||
|
Log.e( TAG, e.toString(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
public static String getExternalFilesDir( Context ctx )
|
public static String getExternalFilesDir( Context ctx )
|
||||||
{
|
{
|
||||||
File f = ctx.getExternalFilesDir( null );
|
if( externalFilesDir != null )
|
||||||
|
return externalFilesDir;
|
||||||
if( f == null )
|
try
|
||||||
{
|
{
|
||||||
f = new File( getDefaultXashPath() );
|
if( sdk >= 8 )
|
||||||
|
{
|
||||||
|
Thread t = new GetExternalFilesDir(ctx);
|
||||||
|
t.start();
|
||||||
|
t.join(2000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
catch(Exception e)
|
||||||
f.mkdirs();
|
{
|
||||||
|
Log.e( TAG, e.toString(), e);
|
||||||
return f.getAbsolutePath();
|
externalFilesDir = getDefaultXashPath();
|
||||||
|
}
|
||||||
|
if( externalFilesDir == null )
|
||||||
|
externalFilesDir = getDefaultXashPath();
|
||||||
|
return externalFilesDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isLandscapeOrientation( Activity act )
|
public static boolean isLandscapeOrientation( Activity act )
|
||||||
|
|
Loading…
Add table
Reference in a new issue