Answer the question
In order to leave comments, you need to log in
How to solve error with following hyperlinks in WebView?
There is a simple WebView that opens a text document. Code below if needed
public class ValkyriaViewActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_stigmata_view);
WebView webView = findViewById(R.id.webView);
webView.setBackgroundColor(Color.parseColor("#CCCCCC"));
Intent intent = getIntent();
//получаем строку и формируем имя ресурса
String resName = "v" + intent.getIntExtra("mValkyrieName", 0) + "s" + intent.getIntExtra("mSuitName", 0);
Log.i("name", resName);
Context context = getBaseContext();
String text = readRawTextFile(context, getResources().getIdentifier(resName,
"raw", "хххх"));
webView.loadDataWithBaseURL("file:///android_res/raw/",text,"txt/html","UTF-8",null);
}
private String readRawTextFile(Context context, int resId)
{
InputStream inputStream = context.getResources().openRawResource(resId);
InputStreamReader inputReader = new InputStreamReader(inputStream);
BufferedReader buffReader = new BufferedReader(inputReader);
String line;
StringBuilder builder = new StringBuilder();
try {
while (( line = buffReader.readLine()) != null) {
builder.append(line);
builder.append("\n");
}
} catch (IOException e) {
return null;
}
return builder.toString();
}
}
<a href="file:///android_res/raw/open/ххх">........</a>
E/AndroidRuntime: FATAL EXCEPTION: main
Process: ххх, PID: 27080
android.os.FileUriExposedException: file:///android_res/raw/v0s1.txt exposed beyond app through Intent.getData()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question