add user-facing error reporting
This commit is contained in:
parent
89ce54c53a
commit
1fd99ae3b4
@ -35,6 +35,7 @@ android {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||||
|
implementation 'com.google.android.material:material:1.1.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
def props = new Properties()
|
def props = new Properties()
|
||||||
|
@ -27,6 +27,8 @@ import androidx.appcompat.app.AppCompatActivity;
|
|||||||
import androidx.loader.app.LoaderManager;
|
import androidx.loader.app.LoaderManager;
|
||||||
import androidx.loader.content.Loader;
|
import androidx.loader.content.Loader;
|
||||||
|
|
||||||
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -96,6 +98,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|||||||
private WebView mWebView;
|
private WebView mWebView;
|
||||||
private TextView mTextView;
|
private TextView mTextView;
|
||||||
private Toast mToast;
|
private Toast mToast;
|
||||||
|
private Snackbar snackbar;
|
||||||
|
|
||||||
private class Channel {
|
private class Channel {
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
@ -280,18 +283,15 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|||||||
// loader manager impl so that the result will be delivered.
|
// loader manager impl so that the result will be delivered.
|
||||||
LoaderManager.getInstance(this);
|
LoaderManager.getInstance(this);
|
||||||
|
|
||||||
|
snackbar = Snackbar.make(findViewById(R.id.webview), "", Snackbar.LENGTH_LONG);
|
||||||
|
|
||||||
final Intent intent = getIntent();
|
final Intent intent = getIntent();
|
||||||
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
||||||
if (!"application/pdf".equals(intent.getType())) {
|
if (!"application/pdf".equals(intent.getType())) {
|
||||||
Log.e(TAG, "invalid mime type");
|
snackbar.setText(R.string.invalid_mime_type).show();
|
||||||
finish();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mUri = intent.getData();
|
mUri = intent.getData();
|
||||||
if ("file".equals(mUri.getScheme())) {
|
|
||||||
Log.e(TAG, "invalid legacy file URI: " + mUri);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mPage = 1;
|
mPage = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,6 +302,11 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|||||||
mDocumentOrientationDegrees = savedInstanceState.getInt(STATE_DOCUMENT_ORIENTATION_DEGREES);
|
mDocumentOrientationDegrees = savedInstanceState.getInt(STATE_DOCUMENT_ORIENTATION_DEGREES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ("file".equals(mUri.getScheme())) {
|
||||||
|
snackbar.setText(R.string.legacy_file_uri).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (mUri != null) {
|
if (mUri != null) {
|
||||||
loadPdf();
|
loadPdf();
|
||||||
}
|
}
|
||||||
@ -330,7 +335,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|||||||
}
|
}
|
||||||
mInputStream = getContentResolver().openInputStream(mUri);
|
mInputStream = getContentResolver().openInputStream(mUri);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG, "failed to open URI: " + mUri);
|
snackbar.setText(R.string.io_error).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mWebView.loadUrl("https://localhost/viewer.html");
|
mWebView.loadUrl("https://localhost/viewer.html");
|
||||||
|
@ -16,4 +16,8 @@
|
|||||||
|
|
||||||
<string name="document_properties_invalid_date">Invalid date</string>
|
<string name="document_properties_invalid_date">Invalid date</string>
|
||||||
<string name="document_properties_retrieval_failed">Failed to obtain document metadata</string>
|
<string name="document_properties_retrieval_failed">Failed to obtain document metadata</string>
|
||||||
|
|
||||||
|
<string name="invalid_mime_type">Cannot open file with invalid mime type</string>
|
||||||
|
<string name="legacy_file_uri">Cannot open legacy file paths from insecure apps</string>
|
||||||
|
<string name="io_error">Received I/O error trying to open content</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user