mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-22 09:01:57 -05:00
Still use file:// urls for devices earlier than android 6.0
This commit is contained in:
parent
2582f0a182
commit
57713d5c5d
4 changed files with 27 additions and 10 deletions
|
@ -13,7 +13,7 @@
|
|||
<application android:icon="@mipmap/ccicon" android:label="ClassiCube">
|
||||
<provider
|
||||
android:name="com.classicube.CCFileProvider"
|
||||
android:authorities="com.classicube.android.client.ccfiles"
|
||||
android:authorities="com.classicube.android.client.provider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true" >
|
||||
</provider>
|
||||
|
|
|
@ -12,11 +12,12 @@ import android.database.Cursor;
|
|||
import android.database.MatrixCursor;
|
||||
import android.net.Uri;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.provider.MediaStore;
|
||||
import android.provider.OpenableColumns;
|
||||
|
||||
public class CCFileProvider extends ContentProvider
|
||||
{
|
||||
final static String[] DEFAULT_COLUMNS = { OpenableColumns.DISPLAY_NAME, OpenableColumns.SIZE };
|
||||
final static String[] DEFAULT_COLUMNS = { OpenableColumns.DISPLAY_NAME, OpenableColumns.SIZE, MediaStore.MediaColumns.DATA };
|
||||
File root;
|
||||
|
||||
@Override
|
||||
|
@ -33,11 +34,11 @@ public class CCFileProvider extends ContentProvider
|
|||
@Override
|
||||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
|
||||
File file = getFileForUri(uri);
|
||||
// can be null when caller is requesting all supported columns
|
||||
// can be null when caller is requesting all columns
|
||||
if (projection == null) projection = DEFAULT_COLUMNS;
|
||||
|
||||
ArrayList<String> cols = new ArrayList<String>(2);
|
||||
ArrayList<Object> vals = new ArrayList<Object>(2);
|
||||
ArrayList<String> cols = new ArrayList<String>(3);
|
||||
ArrayList<Object> vals = new ArrayList<Object>(3);
|
||||
|
||||
for (String column : projection) {
|
||||
if (column.equals(OpenableColumns.DISPLAY_NAME)) {
|
||||
|
@ -46,6 +47,9 @@ public class CCFileProvider extends ContentProvider
|
|||
} else if (column.equals(OpenableColumns.SIZE)) {
|
||||
cols.add(OpenableColumns.SIZE);
|
||||
vals.add(file.length());
|
||||
} else if (column.equals(MediaStore.MediaColumns.DATA)) {
|
||||
cols.add(MediaStore.MediaColumns.DATA);
|
||||
vals.add(file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,7 +96,7 @@ public class CCFileProvider extends ContentProvider
|
|||
// See AndroidManifest.xml for authority
|
||||
return new Uri.Builder()
|
||||
.scheme("content")
|
||||
.authority("com.classicube.android.client.ccfiles")
|
||||
.authority("com.classicube.android.client.provider")
|
||||
.encodedPath(Uri.encode(path, "/"))
|
||||
.build();
|
||||
}
|
||||
|
|
|
@ -794,7 +794,17 @@ public class MainActivity extends Activity
|
|||
|
||||
public String shareScreenshot(String path) {
|
||||
try {
|
||||
Uri uri = CCFileProvider.getUriForFile("screenshots", path);
|
||||
Uri uri;
|
||||
if (android.os.Build.VERSION.SDK_INT >= 23){ // android 6.0
|
||||
uri = CCFileProvider.getUriForFile("screenshots/" + path);
|
||||
} else {
|
||||
// when trying to use content:// URIs on my android 4.0.3 test device
|
||||
// - 1 app crashed
|
||||
// - 1 app wouldn't show image previews
|
||||
// so fallback to file:// on older devices as they seem to reliably work
|
||||
File file = new File(getGameDataDirectory() + "/screenshots/" + path);
|
||||
uri = Uri.fromFile(file);
|
||||
}
|
||||
Intent intent = new Intent();
|
||||
|
||||
intent.setAction(Intent.ACTION_SEND);
|
||||
|
|
|
@ -179,9 +179,12 @@ build_android() {
|
|||
# https://github.com/skanti/Android-Manual-Build-Command-Line/blob/master/hello-jni/Makefile
|
||||
# https://github.com/skanti/Android-Manual-Build-Command-Line/blob/master/hello-jni/CMakeLists.txt
|
||||
|
||||
# compile interop java file into its multiple .class files
|
||||
javac java/com/classicube/MainActivity.java -d ./obj -classpath $SDK_ROOT/android.jar
|
||||
# compile java files into multiple .class files
|
||||
cd $ROOT_DIR/android/app/src/main/java/com/classicube
|
||||
javac *.java -d $ROOT_DIR/android/app/src/main/obj -classpath $SDK_ROOT/android.jar
|
||||
if [ $? -ne 0 ]; then echo "Failed to compile Android Java" >> "$ERRS_FILE"; fi
|
||||
|
||||
cd $ROOT_DIR/android/app/src/main
|
||||
# compile the multiple .class files into one .dex file
|
||||
$TOOLS_ROOT/dx --dex --output=obj/classes.dex ./obj
|
||||
# create initial .apk with packaged version of resources
|
||||
|
|
Loading…
Reference in a new issue