Skip to content

Commit

Permalink
Fix android app crashing if opening file/URI without app already runn…
Browse files Browse the repository at this point in the history
…ing.

The native function setInitialFileToLoad() wasn't being found, because I messed up the naming of the function in C++ (left out a "_InterSpec" in the function name - it needs two).
Fixed up a few other small things in the Android client.
  • Loading branch information
wcjohns committed Sep 9, 2023
1 parent 55ad4a3 commit 623b5ea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion target/android/InterSpec/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ android {
// Android 4 (Kit Kat) is level 19. Android 6 (Marshmallow - e.x., Nexus 7) is level 23.
minSdkVersion 19
targetSdkVersion 33
versionCode 14
versionCode 15
versionName "1.0.11"
// testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,19 @@ public static void saveFileFromTempLocation( String location, String displayName

public String getDisplayFileName( Uri result )
{
String name = null;
String name = null;
Cursor cursor = InterSpec.this.getContentResolver().query(result, null, null, null, null, null);
try
{
if( cursor != null && cursor.moveToFirst() )
name = cursor.getString( cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME) );
if( cursor != null && cursor.moveToFirst() )
name = cursor.getString(cursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME));
}finally
{
if( cursor != null )
cursor.close();
}

return name;
return name;
}//public String getDisplayFileName( Uri result )

public String copyUriToTmpDir( Uri result, final String displayName )
Expand Down Expand Up @@ -267,11 +267,13 @@ public String copyUriToTmpDir( Uri result, final String displayName )

public void openFileInInterSpec( Uri result )
{
Log.d("openFileInInterSpec", "Got URI" );
Log.d("openFileInInterSpec", "Got URI and interspecID='" + interspecID + "', httpPort=" + httpPort );

if( result == null )
return;



String scheme = result.getScheme().toLowerCase();
if( scheme.contentEquals("interspec") || scheme.contentEquals("raddata") )
{
Expand Down Expand Up @@ -574,7 +576,7 @@ public void run() {

setTempDir( getCacheDir().getPath() );

Log.d("onCreate", "Starting server");
Log.i("onCreate", "Starting server");
super.onCreate(savedInstanceState);

this.requestWindowFeature( android.view.Window.FEATURE_NO_TITLE );
Expand Down Expand Up @@ -688,7 +690,13 @@ public boolean shouldOverrideUrlLoading(WebView view, String url){
if( fileUri != null )
{
String scheme = fileUri.getScheme();
if( ContentResolver.SCHEME_CONTENT.equals(scheme) )
Log.d("onCreate", "scheme: '" + scheme + "'" );

if( scheme.equalsIgnoreCase("raddata") || scheme.equalsIgnoreCase("interspec") )
{
int status = setInitialFileToLoad( interspecID, fileUri.toString() );
Log.d("onCreate", "ACTION_VIEW, Will open URI on load; status=" + status );
}else if( ContentResolver.SCHEME_CONTENT.equals(scheme) )
{
// handle as content uri
Log.d("onCreate", "ACTION_VIEW, fileUri is a SCHEME_CONTENT" );
Expand Down Expand Up @@ -727,7 +735,7 @@ else if( Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null )
Log.d("onCreate", "Will load 'http://127.0.0.1:" + httpPort + "/?apptoken=" + interspecID + "'");
webview.loadUrl("http://127.0.0.1:" + httpPort + "/?apptoken=" + interspecID );

WebView.setWebContentsDebuggingEnabled(true);
// WebView.setWebContentsDebuggingEnabled(true);
}//if( httpPort == 0 )

Log.d("onCreate", "done starting server ish");
Expand Down
4 changes: 2 additions & 2 deletions target/android/android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ JNIEXPORT
JNIEXPORT
jint
JNICALL
Java_gov_sandia_InterSpec_removeSessionToken( JNIEnv* env, jobject thiz, jstring jtoken )
Java_gov_sandia_InterSpec_InterSpec_removeSessionToken( JNIEnv* env, jobject thiz, jstring jtoken )
{
const std::string token = std::string(env->GetStringUTFChars(jtoken, nullptr));

Expand All @@ -603,7 +603,7 @@ JNIEXPORT
JNIEXPORT
jint
JNICALL
Java_gov_sandia_InterSpec_setInitialFileToLoad( JNIEnv* env, jobject thiz, jstring jtoken, jstring jfilepath )
Java_gov_sandia_InterSpec_InterSpec_setInitialFileToLoad( JNIEnv* env, jobject thiz, jstring jtoken, jstring jfilepath )
{
const std::string token = std::string(env->GetStringUTFChars(jtoken, nullptr));
const std::string filepath = std::string(env->GetStringUTFChars(jfilepath, nullptr));
Expand Down

0 comments on commit 623b5ea

Please sign in to comment.