mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-10 16:03:15 -04:00
Still use file:// urls for devices earlier than android 6.0
This commit is contained in:
parent
2582f0a182
commit
57713d5c5d
@ -13,7 +13,7 @@
|
|||||||
<application android:icon="@mipmap/ccicon" android:label="ClassiCube">
|
<application android:icon="@mipmap/ccicon" android:label="ClassiCube">
|
||||||
<provider
|
<provider
|
||||||
android:name="com.classicube.CCFileProvider"
|
android:name="com.classicube.CCFileProvider"
|
||||||
android:authorities="com.classicube.android.client.ccfiles"
|
android:authorities="com.classicube.android.client.provider"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:grantUriPermissions="true" >
|
android:grantUriPermissions="true" >
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -12,11 +12,12 @@ import android.database.Cursor;
|
|||||||
import android.database.MatrixCursor;
|
import android.database.MatrixCursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
|
import android.provider.MediaStore;
|
||||||
import android.provider.OpenableColumns;
|
import android.provider.OpenableColumns;
|
||||||
|
|
||||||
public class CCFileProvider extends ContentProvider
|
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;
|
File root;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -33,11 +34,11 @@ public class CCFileProvider extends ContentProvider
|
|||||||
@Override
|
@Override
|
||||||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
|
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
|
||||||
File file = getFileForUri(uri);
|
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;
|
if (projection == null) projection = DEFAULT_COLUMNS;
|
||||||
|
|
||||||
ArrayList<String> cols = new ArrayList<String>(2);
|
ArrayList<String> cols = new ArrayList<String>(3);
|
||||||
ArrayList<Object> vals = new ArrayList<Object>(2);
|
ArrayList<Object> vals = new ArrayList<Object>(3);
|
||||||
|
|
||||||
for (String column : projection) {
|
for (String column : projection) {
|
||||||
if (column.equals(OpenableColumns.DISPLAY_NAME)) {
|
if (column.equals(OpenableColumns.DISPLAY_NAME)) {
|
||||||
@ -46,6 +47,9 @@ public class CCFileProvider extends ContentProvider
|
|||||||
} else if (column.equals(OpenableColumns.SIZE)) {
|
} else if (column.equals(OpenableColumns.SIZE)) {
|
||||||
cols.add(OpenableColumns.SIZE);
|
cols.add(OpenableColumns.SIZE);
|
||||||
vals.add(file.length());
|
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
|
// See AndroidManifest.xml for authority
|
||||||
return new Uri.Builder()
|
return new Uri.Builder()
|
||||||
.scheme("content")
|
.scheme("content")
|
||||||
.authority("com.classicube.android.client.ccfiles")
|
.authority("com.classicube.android.client.provider")
|
||||||
.encodedPath(Uri.encode(path, "/"))
|
.encodedPath(Uri.encode(path, "/"))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
@ -794,7 +794,17 @@ public class MainActivity extends Activity
|
|||||||
|
|
||||||
public String shareScreenshot(String path) {
|
public String shareScreenshot(String path) {
|
||||||
try {
|
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 intent = new Intent();
|
||||||
|
|
||||||
intent.setAction(Intent.ACTION_SEND);
|
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/Makefile
|
||||||
# https://github.com/skanti/Android-Manual-Build-Command-Line/blob/master/hello-jni/CMakeLists.txt
|
# https://github.com/skanti/Android-Manual-Build-Command-Line/blob/master/hello-jni/CMakeLists.txt
|
||||||
|
|
||||||
# compile interop java file into its multiple .class files
|
# compile java files into multiple .class files
|
||||||
javac java/com/classicube/MainActivity.java -d ./obj -classpath $SDK_ROOT/android.jar
|
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
|
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
|
# compile the multiple .class files into one .dex file
|
||||||
$TOOLS_ROOT/dx --dex --output=obj/classes.dex ./obj
|
$TOOLS_ROOT/dx --dex --output=obj/classes.dex ./obj
|
||||||
# create initial .apk with packaged version of resources
|
# create initial .apk with packaged version of resources
|
||||||
|
Loading…
x
Reference in New Issue
Block a user