mirror of
https://github.com/scratchfoundation/scratchjr.git
synced 2024-11-28 18:15:37 -05:00
Fix can't import sjr
This commit is contained in:
parent
f90b6840e3
commit
d7bd9789dd
2 changed files with 34 additions and 8 deletions
|
@ -7,7 +7,7 @@
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||||
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
|
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
|
||||||
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||||
|
|
||||||
<uses-feature android:name="android.hardware.camera" android:required="false" />
|
<uses-feature android:name="android.hardware.camera" android:required="false" />
|
||||||
<uses-feature android:name="android.hardware.microphone" android:required="false" />
|
<uses-feature android:name="android.hardware.microphone" android:required="false" />
|
||||||
|
@ -40,7 +40,8 @@
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
<category android:name="android.intent.category.BROWSABLE" />
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
<data android:mimeType="@string/share_mimetype" />
|
<data android:scheme="file" />
|
||||||
|
<data android:mimeType="*/*" />
|
||||||
<data android:pathPattern="@string/share_extension_filter" />
|
<data android:pathPattern="@string/share_extension_filter" />
|
||||||
<data android:host="*" />
|
<data android:host="*" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.Manifest;
|
||||||
import android.animation.ObjectAnimator;
|
import android.animation.ObjectAnimator;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
@ -37,6 +38,8 @@ import com.google.android.gms.analytics.HitBuilders;
|
||||||
import com.google.android.gms.analytics.Tracker;
|
import com.google.android.gms.analytics.Tracker;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -147,9 +150,8 @@ public class ScratchJrActivity
|
||||||
CookieManager.getInstance().setAcceptCookie(true);
|
CookieManager.getInstance().setAcceptCookie(true);
|
||||||
CookieManager.setAcceptFileSchemeCookies(true);
|
CookieManager.setAcceptFileSchemeCookies(true);
|
||||||
|
|
||||||
String PROJECT_MIMETYPE = getApplicationContext().getString(R.string.share_mimetype);
|
|
||||||
Intent it = getIntent();
|
Intent it = getIntent();
|
||||||
if (it != null && it.getType() != null && it.getType().equals(PROJECT_MIMETYPE)) {
|
if (it != null && it.getData() != null) {
|
||||||
receiveProject(it.getData());
|
receiveProject(it.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,11 +173,20 @@ public class ScratchJrActivity
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
requestPermissions();
|
requestPermissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void requestExtStoragePermissions() {
|
||||||
|
int readExtPermissionResult = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||||
|
if (readExtPermissionResult != PackageManager.PERMISSION_GRANTED) {
|
||||||
|
int requestCode = 2;
|
||||||
|
ActivityCompat.requestPermissions(this,
|
||||||
|
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, requestCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void requestPermissions() {
|
public void requestPermissions() {
|
||||||
|
requestExtStoragePermissions();
|
||||||
cameraPermissionResult = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
|
cameraPermissionResult = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
|
||||||
micPermissionResult = ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO);
|
micPermissionResult = ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO);
|
||||||
|
|
||||||
|
@ -293,17 +304,31 @@ public class ScratchJrActivity
|
||||||
@Override
|
@Override
|
||||||
protected void onNewIntent(Intent it) {
|
protected void onNewIntent(Intent it) {
|
||||||
super.onNewIntent(it);
|
super.onNewIntent(it);
|
||||||
String PROJECT_MIMETYPE = getApplicationContext().getString(R.string.share_mimetype);
|
if (it != null && it.getData() != null) {
|
||||||
if (it != null && it.getType() != null && it.getType().equals(PROJECT_MIMETYPE)) {
|
|
||||||
receiveProject(it.getData());
|
receiveProject(it.getData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void receiveProject(Uri projectUri) {
|
private void receiveProject(Uri projectUri) {
|
||||||
|
File projectFile = null;
|
||||||
|
String scheme = projectUri.getScheme();
|
||||||
|
if (scheme != null) {
|
||||||
|
if (scheme.equals(ContentResolver.SCHEME_FILE)) {
|
||||||
|
String filePath = projectUri.getPath();
|
||||||
|
projectFile = filePath != null ? new File(filePath) : null;
|
||||||
|
} else if (!scheme.equals(ContentResolver.SCHEME_CONTENT)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
// Read the project one byte at a time into a buffer
|
// Read the project one byte at a time into a buffer
|
||||||
ByteArrayOutputStream projectData = new ByteArrayOutputStream();
|
ByteArrayOutputStream projectData = new ByteArrayOutputStream();
|
||||||
try {
|
try {
|
||||||
InputStream is = getContentResolver().openInputStream(projectUri);
|
InputStream is = null;
|
||||||
|
if (projectFile != null) {
|
||||||
|
is = new FileInputStream(projectFile);
|
||||||
|
} else {
|
||||||
|
getContentResolver().openInputStream(projectUri);
|
||||||
|
}
|
||||||
byte[] readByte = new byte[1];
|
byte[] readByte = new byte[1];
|
||||||
while ((is.read(readByte)) == 1) {
|
while ((is.read(readByte)) == 1) {
|
||||||
projectData.write(readByte[0]);
|
projectData.write(readByte[0]);
|
||||||
|
|
Loading…
Reference in a new issue