Merge pull request #259 from chrisgarrity/content-import-fix

Don’t export as email message, and be less strict about import requirements
This commit is contained in:
chrisgarrity 2020-04-21 07:53:32 -04:00 committed by GitHub
commit fe2ad22efb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 12 deletions

View file

@ -40,12 +40,17 @@
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:scheme="content" />
<data android:mimeType="*/*" />
<data android:pathPattern="@string/share_extension_filter" />
<!-- These additional pathPattern blocks are to allow for paths with
additional periods in them. See:
http://stackoverflow.com/questions/3400072/pathpattern-to-match-file-extension-does-not-work-if-a-period-exists-elsewhere-i/8599921 -->
<data android:pathPattern="@{`.*\\.` + @string/share_extension_filter}"/>
<data android:pathPattern="@{`.*\\..*\\.` + @string/share_extension_filter}"/>
<data android:pathPattern="@{`.*\\..*\\..*\\.` + @string/share_extension_filter}"/>
<data android:pathPattern="@{`.*\\..*\\..*\\..*\\.` + @string/share_extension_filter}"/>
<data android:pathPattern="@{`.*\\..*\\..*\\..*\\..*\\.` + @string/share_extension_filter}"/>
<data android:host="*" />
<data android:scheme="file" />
<data android:scheme="content" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
@ -56,6 +61,16 @@
<data android:mimeType="@string/share_mimetype" />
<data android:host="*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:scheme="content" />
<data android:mimeType="application/octet-stream" />
<data android:host="*" />
</intent-filter>
</activity>
<receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver"

View file

@ -3,8 +3,6 @@ package org.scratchjr.android;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@ -350,7 +348,7 @@ public class JavaScriptDirectInterface {
public String scratchjr_cameracheck() {
return _activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY) ? "1" : "0";
}
@JavascriptInterface
public boolean scratchjr_has_multiple_cameras() {
return Camera.getNumberOfCameras() > 1;
@ -582,10 +580,13 @@ public class JavaScriptDirectInterface {
File tempFile;
String extension;
String mimetype;
if (BuildConfig.APPLICATION_ID.equals("org.pbskids.scratchjr")) {
extension = ".psjr";
mimetype = "application/x-pbskids-scratchjr-project";
} else {
extension = ".sjr";
mimetype = "application/x-scratchjr-project";
}
try {
@ -602,17 +603,18 @@ public class JavaScriptDirectInterface {
}
final Intent it = new Intent(Intent.ACTION_SEND);
it.setType("message/rfc822");
it.setType(mimetype);
it.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {});
it.putExtra(android.content.Intent.EXTRA_SUBJECT, emailSubject);
it.putExtra(android.content.Intent.EXTRA_SUBJECT, fileName);
it.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(emailBody));
// The stream data is a reference to the temporary file provided by our contentprovider
it.putExtra(Intent.EXTRA_STREAM,
Uri.parse("content://" + ShareContentProvider.AUTHORITY + "/"
+ fileName));
Intent shareIntent = Intent.createChooser(it, null);
_activity.startActivity(it);
_activity.startActivity(shareIntent);
}
// Analytics

View file

@ -310,15 +310,20 @@ public class ScratchJrActivity
String scheme = projectUri.getScheme();
Log.i(LOG_TAG, "receiveProject(scheme): " + scheme);
Log.i(LOG_TAG, "receiveProject(path): " + projectUri.getPath());
if (scheme == null || !(scheme.equals(ContentResolver.SCHEME_FILE) || scheme.equals(ContentResolver.SCHEME_CONTENT)) ||
!projectUri.getPath().matches(PROJECT_EXTENSION)) {
// if scheme isn't file or content, skip import
if (scheme == null || !(scheme.equals(ContentResolver.SCHEME_FILE) || scheme.equals(ContentResolver.SCHEME_CONTENT))) {
return;
}
// if scheme is file, then skip if filename doesn't have scratchjr project extension
if (scheme.equals(ContentResolver.SCHEME_FILE) && !projectUri.getPath().matches(PROJECT_EXTENSION)) {
return;
}
// Read the project one byte at a time into a buffer
ByteArrayOutputStream projectData = new ByteArrayOutputStream();
try {
InputStream is = getContentResolver().openInputStream(projectUri);
byte[] readByte = new byte[1];
while ((is.read(readByte)) == 1) {
projectData.write(readByte[0]);