Код: Выделить всё
Код: Выделить всё
package com.guerrilla.innov8coworking;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
import com.facebook.react.defaults.DefaultReactActivityDelegate;
import android.os.Bundle;
import org.devio.rn.splashscreen.SplashScreen;
import android.Manifest;
import android.app.DownloadManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.util.Log;
import android.webkit.MimeTypeMap;
import android.webkit.URLUtil;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import java.util.Arrays;
public class MainActivity extends ReactActivity {
private static final int REQUEST_WRITE_STORAGE = 0;
private String downloadUrl;
@Override
protected void onCreate(Bundle savedInstanceState) {
final boolean setFullScreen = true;
Log.d("Jugni", "Hii I am on create method");
SplashScreen.show(this, R.style.SplashScreenTheme, setFullScreen);
super.onCreate(savedInstanceState);
// Check and request permissions when the app starts
if (Build.VERSION.SDK_INT >= 23) {
Log.d("Jugni", "Hii I am inside version 24" + String.valueOf(Build.VERSION.SDK_INT));
Log.d("Jugni", "Hii my permission is" + String.valueOf(Manifest.permission.WRITE_EXTERNAL_STORAGE));
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
Log.d("Jugni", "Hii my permission is" + String.valueOf(ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)));
Log.d("Jugni", "Hii I am inside check self permission");
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_WRITE_STORAGE);
Log.d("Jugni", "Hii my new permission is" + String.valueOf(ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)));
Log.d("Jugni", "Request permission completed");
} else {
Log.d("Jugni", "Permission already granted");
}
}
}
private void downloadFile(String url) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setTitle("Vertretungsplan");
request.setDescription("wird heruntergeladen");
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
String filename = URLUtil.guessFileName(url, null, MimeTypeMap.getFileExtensionFromUrl(url));
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
Log.d("Jugni", "Inside Request permission block, requestCode: " + requestCode + ", permissions: " + Arrays.toString(permissions) + ", grantResults: " + Arrays.toString(grantResults));
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_WRITE_STORAGE) {
Log.d("Jugni", "GrantResults length" + String.valueOf(grantResults.length));
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Log.d("Jugni", String.valueOf( grantResults[0]));
Log.d("Jugni", downloadUrl);
// Permission granted, proceed with the file download
if (downloadUrl != null) {
downloadFile(downloadUrl);
}
} else {
// Permission denied, handle accordingly
}
}
}
/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "ows_app_rn";
}
/**
* Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link
* DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React
* (aka React 18) with two boolean flags.
*/
@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new DefaultReactActivityDelegate(
this,
getMainComponentName(),
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
DefaultNewArchitectureEntryPoint.getFabricEnabled());
}
}
Код: Выделить всё
ext {
buildToolsVersion = "34.0.0"
minSdkVersion = 24
compileSdkVersion = 33
targetSdkVersion = 34
androidXCore = "1.0.2"
// We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
ndkVersion = "23.1.7779620"
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... and-higher