From 7d7f4c435d336d7771f6a738999db8e14488f394 Mon Sep 17 00:00:00 2001 From: Erwan Croze Date: Tue, 11 Apr 2017 11:33:35 +0200 Subject: [PATCH] Fix text sharing --- .../org/linphone/LinphoneActivity.java | 7 +++ .../linphone/LinphoneLauncherActivity.java | 50 ++++++++++--------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/android/org/linphone/LinphoneActivity.java b/src/android/org/linphone/LinphoneActivity.java index fab6760fa..36cc41646 100644 --- a/src/android/org/linphone/LinphoneActivity.java +++ b/src/android/org/linphone/LinphoneActivity.java @@ -1382,6 +1382,13 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick } } } + + Intent intent = getIntent(); + + if (intent.getStringExtra("msgShared") != null) + displayChat(null, intent.getStringExtra("msgShared")); + + doNotGoToCallActivity = false; isOnBackground = false; } diff --git a/src/android/org/linphone/LinphoneLauncherActivity.java b/src/android/org/linphone/LinphoneLauncherActivity.java index 8d7672dd7..7831c6ad9 100644 --- a/src/android/org/linphone/LinphoneLauncherActivity.java +++ b/src/android/org/linphone/LinphoneLauncherActivity.java @@ -40,7 +40,7 @@ import android.os.Handler; public class LinphoneLauncherActivity extends Activity { private Handler mHandler; - private ServiceWaitThread mThread; + private ServiceWaitThread mServiceThread; @Override protected void onCreate(Bundle savedInstanceState) { @@ -54,19 +54,19 @@ public class LinphoneLauncherActivity extends Activity { mHandler = new Handler(); - Intent intent = getIntent(); + if (LinphoneService.isReady()) { - onServiceReady(intent); + onServiceReady(); } else { // start linphone as background startService(new Intent(ACTION_MAIN).setClass(this, LinphoneService.class)); - mThread = new ServiceWaitThread(); - mThread.start(); + mServiceThread = new ServiceWaitThread(); + mServiceThread.start(); } } - protected void onServiceReady(Intent intent) { + protected void onServiceReady() { final Class classToStart; if (getResources().getBoolean(R.bool.show_tutorials_instead_of_app)) { classToStart = TutorialLauncherActivity.class; @@ -76,36 +76,38 @@ public class LinphoneLauncherActivity extends Activity { classToStart = LinphoneActivity.class; } - String sharedText = null; - if (intent != null) { - String action = intent.getAction(); - String type = intent.getType(); - - if (Intent.ACTION_SEND.equals(action) && type != null) { - if ("text/plain".equals(type)) { - sharedText = intent.getStringExtra(Intent.EXTRA_TEXT); - } - } - } - // We need LinphoneService to start bluetoothManager if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) { BluetoothManager.getInstance().initBluetooth(); } - final String finalSharedText = sharedText; mHandler.postDelayed(new Runnable() { @Override public void run() { - startActivity(new Intent().setClass(LinphoneLauncherActivity.this, classToStart).setData(getIntent().getData())); - if (finalSharedText != null) { - LinphoneActivity.instance().displayChat(null, finalSharedText); + Intent newIntent = new Intent(LinphoneLauncherActivity.this, classToStart); + Intent intent = getIntent(); + String msgShared = null; + if (intent != null) { + String action = intent.getAction(); + String type = intent.getType(); + newIntent.setData(intent.getData()); + if (Intent.ACTION_SEND.equals(action) && type != null) { + if ("text/plain".equals(type) && intent.getStringExtra(Intent.EXTRA_TEXT) != null) { + msgShared = intent.getStringExtra(Intent.EXTRA_TEXT); + newIntent.putExtra("msgShared", msgShared); + } + } } + startActivity(newIntent); + if (classToStart == LinphoneActivity.class && LinphoneActivity.isInstanciated() && msgShared != null) { + LinphoneActivity.instance().displayChat(null, msgShared); + } finish(); } }, 1000); } + private class ServiceWaitThread extends Thread { public void run() { while (!LinphoneService.isReady()) { @@ -118,10 +120,10 @@ public class LinphoneLauncherActivity extends Activity { mHandler.post(new Runnable() { @Override public void run() { - onServiceReady(null); + onServiceReady(); } }); - mThread = null; + mServiceThread = null; } } }