Fix text sharing

This commit is contained in:
Erwan Croze 2017-04-11 11:33:35 +02:00
parent ae6c8855b3
commit 7d7f4c435d
2 changed files with 33 additions and 24 deletions

View file

@ -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; doNotGoToCallActivity = false;
isOnBackground = false; isOnBackground = false;
} }

View file

@ -40,7 +40,7 @@ import android.os.Handler;
public class LinphoneLauncherActivity extends Activity { public class LinphoneLauncherActivity extends Activity {
private Handler mHandler; private Handler mHandler;
private ServiceWaitThread mThread; private ServiceWaitThread mServiceThread;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -54,19 +54,19 @@ public class LinphoneLauncherActivity extends Activity {
mHandler = new Handler(); mHandler = new Handler();
Intent intent = getIntent();
if (LinphoneService.isReady()) { if (LinphoneService.isReady()) {
onServiceReady(intent); onServiceReady();
} else { } else {
// start linphone as background // start linphone as background
startService(new Intent(ACTION_MAIN).setClass(this, LinphoneService.class)); startService(new Intent(ACTION_MAIN).setClass(this, LinphoneService.class));
mThread = new ServiceWaitThread(); mServiceThread = new ServiceWaitThread();
mThread.start(); mServiceThread.start();
} }
} }
protected void onServiceReady(Intent intent) { protected void onServiceReady() {
final Class<? extends Activity> classToStart; final Class<? extends Activity> classToStart;
if (getResources().getBoolean(R.bool.show_tutorials_instead_of_app)) { if (getResources().getBoolean(R.bool.show_tutorials_instead_of_app)) {
classToStart = TutorialLauncherActivity.class; classToStart = TutorialLauncherActivity.class;
@ -76,36 +76,38 @@ public class LinphoneLauncherActivity extends Activity {
classToStart = LinphoneActivity.class; 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 // We need LinphoneService to start bluetoothManager
if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) { if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) {
BluetoothManager.getInstance().initBluetooth(); BluetoothManager.getInstance().initBluetooth();
} }
final String finalSharedText = sharedText;
mHandler.postDelayed(new Runnable() { mHandler.postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
startActivity(new Intent().setClass(LinphoneLauncherActivity.this, classToStart).setData(getIntent().getData())); Intent newIntent = new Intent(LinphoneLauncherActivity.this, classToStart);
if (finalSharedText != null) { Intent intent = getIntent();
LinphoneActivity.instance().displayChat(null, finalSharedText); 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(); finish();
} }
}, 1000); }, 1000);
} }
private class ServiceWaitThread extends Thread { private class ServiceWaitThread extends Thread {
public void run() { public void run() {
while (!LinphoneService.isReady()) { while (!LinphoneService.isReady()) {
@ -118,10 +120,10 @@ public class LinphoneLauncherActivity extends Activity {
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
onServiceReady(null); onServiceReady();
} }
}); });
mThread = null; mServiceThread = null;
} }
} }
} }