AS: exposed beyond app through Intent.getData()
Я создал небольшую игру, состоящую из 4-х html-страниц. Сейчас после запуска в AS приложение включается. Однако при попытке перейти на другую страницу вылезает ошибка. Часть Logcat, где содержится ошибка:
2020-03-27 13:46:05.794 3575-3575/? E/android.os.Debug: failed to load memtrack module: -2
2020-03-27 13:46:05.912 3575-3575/? E/chromium: [0327/104605.912583:ERROR:elf_dynamic_array_reader.h(61)] tag not found
2020-03-27 13:46:05.951 3575-3575/? E/chromium: [0327/104605.950286:ERROR:file_io_posix.cc(147)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
2020-03-27 13:46:05.951 3575-3575/? E/chromium: [0327/104605.951586:ERROR:file_io_posix.cc(147)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)
2020-03-27 13:46:05.954 3575-3575/? E/chromium: [0327/104605.953192:ERROR:system_snapshot_linux.cc(125)] Couldn't read property ro.product.board
2020-03-27 13:46:06.021 2330-2330/com.example.rublefalling E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.rublefalling, PID: 2330
android.os.FileUriExposedException: file:///android_asset/game.html exposed beyond app through Intent.getData()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1799)
at android.net.Uri.checkFileUriExposed(Uri.java:2346)
at android.content.Intent.prepareToLeaveProcess(Intent.java:8965)
at android.content.Intent.prepareToLeaveProcess(Intent.java:8926)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1517)
at android.app.Activity.startActivityForResult(Activity.java:4225)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:767)
at android.app.Activity.startActivityForResult(Activity.java:4183)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:754)
at android.app.Activity.startActivity(Activity.java:4522)
at android.app.Activity.startActivity(Activity.java:4490)
at android.content.ContextWrapper.startActivity(ContextWrapper.java:356)
at a82.startActivity(PG:3)
at org.chromium.android_webview.AwContentsClientBridge.shouldOverrideUrlLoading(PG:31)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:323)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
2020-03-27 13:46:06.184 1297-1303/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
2020-03-27 13:46:06.302 1640-3587/? E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
2020-03-27 13:46:06.303 1640-3587/? E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
Как я понял, надо использовать FileProvider. С помощью поиска я написал код, который особо не сработал. После многочисленного тырканья я пришёл сюда. Вчера весь день гуглил русско- и англоязычный инет в поисках решения, но ничего не понял. Подскажите, пожалуйста, что нужно, чтобы можно было переходить между страницами?
MainActivity.java:
package com.example.rublefalling;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.FileProvider;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import static android.app.PendingIntent.getActivity;
public class MainActivity extends AppCompatActivity {
protected WebView rublefalling;
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rublefalling = (WebView) findViewById(R.id.rublefalling);
// settings
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
File dirPath = new File (String.valueOf(getFilesDir()));
dirPath.mkdirs();
File newFile = new File(dirPath, "game.html");
Uri uri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider", newFile);
intent.setDataAndType(uri, "application/html");
PackageManager pm = MainActivity.this.getPackageManager();
if (intent.resolveActivity(pm) != null) {
startActivity(intent);
}
rublefalling.setInitialScale(1);
rublefalling.getSettings().setUseWideViewPort(true);
rublefalling.getSettings().setLoadWithOverviewMode(true);
rublefalling.getSettings().setAllowContentAccess(true);
rublefalling.getSettings().setDomStorageEnabled(true);
rublefalling.getSettings().setAllowFileAccessFromFileURLs(true);
rublefalling.getSettings().setAllowUniversalAccessFromFileURLs(true);
// load
rublefalling.loadUrl("file:///android_asset/index.html");
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.rublefalling">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:isGame="true"
android:hardwareAccelerated="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.example.rublefalling.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_path"
/>
</provider>
</application>
</manifest>
provider_path.xml:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path
name="external"
path="." />
<external-files-path
name="external_files"
path="." />
<cache-path
name="cache"
path="." />
<external-cache-path
name="external_cache"
path="." />
<files-path
name="files"
path="." />
</paths>