mirror of
https://github.com/scratchfoundation/scratchjr.git
synced 2024-11-25 00:28:20 -05:00
commit
bca5f433ae
2 changed files with 35 additions and 7 deletions
|
@ -6,7 +6,7 @@
|
|||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<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.microphone" android:required="false" />
|
||||
|
@ -38,12 +38,23 @@
|
|||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:mimeType="@string/share_mimetype" />
|
||||
<data android:scheme="file" />
|
||||
<data android:scheme="content" />
|
||||
<data android:mimeType="*/*" />
|
||||
<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" />
|
||||
<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="@string/share_mimetype" />
|
||||
<data android:host="*" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver"
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.Manifest;
|
|||
import android.animation.ObjectAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
|
@ -146,9 +147,8 @@ public class ScratchJrActivity
|
|||
CookieManager.getInstance().setAcceptCookie(true);
|
||||
CookieManager.setAcceptFileSchemeCookies(true);
|
||||
|
||||
String PROJECT_MIMETYPE = getApplicationContext().getString(R.string.share_mimetype);
|
||||
Intent it = getIntent();
|
||||
if (it != null && it.getType() != null && it.getType().equals(PROJECT_MIMETYPE)) {
|
||||
if (it != null && it.getData() != null) {
|
||||
receiveProject(it.getData());
|
||||
}
|
||||
|
||||
|
@ -169,11 +169,20 @@ public class ScratchJrActivity
|
|||
}, 1000);
|
||||
}
|
||||
});
|
||||
|
||||
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() {
|
||||
requestExtStoragePermissions();
|
||||
cameraPermissionResult = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
|
||||
micPermissionResult = ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO);
|
||||
|
||||
|
@ -291,17 +300,25 @@ public class ScratchJrActivity
|
|||
@Override
|
||||
protected void onNewIntent(Intent it) {
|
||||
super.onNewIntent(it);
|
||||
String PROJECT_MIMETYPE = getApplicationContext().getString(R.string.share_mimetype);
|
||||
if (it != null && it.getType() != null && it.getType().equals(PROJECT_MIMETYPE)) {
|
||||
if (it != null && it.getData() != null) {
|
||||
receiveProject(it.getData());
|
||||
}
|
||||
}
|
||||
|
||||
private void receiveProject(Uri projectUri) {
|
||||
String PROJECT_EXTENSION = getApplicationContext().getString(R.string.share_extension_filter);
|
||||
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)) {
|
||||
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]);
|
||||
|
|
Loading…
Reference in a new issue