/** * MainActivity has a "singleTask" launch mode, which means that if it is currently running and * another intent is launched to open it, instead of creating a new MainActivity it just opens the * current MainActivity. We use this so that when you click on notifications, only one main * activity is ever used. * * <p>onNewIntent() is called every time the homescreen shortcut is tapped, even if the app is * already running in the background. It's also called when the app is launched via other intents * * <p>Docs: * http://developer.android.com/guide/components/tasks-and-back-stack.html#TaskLaunchModes */ @Override public void onNewIntent(Intent intent) { // onNewIntent doesn't change the result of getIntent() by default, so here we set it since // that makes the most sense. setIntent(intent); // This method is called whenever a MainActivity intent is started. Sometimes this is from a // notification; other times it's from the user clicking on the app icon in the home screen long threadId = intent.getLongExtra(EXTRA_THREAD_ID, -1); // The activity can also be launched by clicking on the message button from the contacts app // Check for {sms,mms}{,to}: schemes, in which case we know to open a conversation if (intent.getData() != null) { String data = intent.getData().toString(); String scheme = intent.getData().getScheme(); if (scheme.startsWith("smsto") || scheme.startsWith("mmsto")) { String address = data.replace("smsto:", "").replace("mmsto:", ""); threadId = Utils.getThreadId(this, formatPhoneNumber(address)); } else if (scheme.startsWith("sms") || (scheme.startsWith("mms"))) { String address = data.replace("sms:", "").replace("mms:", ""); threadId = Utils.getThreadId(this, formatPhoneNumber(address)); } } // If it has a thread id, then we know it's from a notification and we can set the // conversation. if (threadId != -1) { Log.v(TAG, "Opening thread: " + threadId); setConversation(threadId); mSlidingMenu.showContent(); } // Otherwise we'll just resume what was previously there, which doesn't require any code. }
@Override public void onBackPressed() { // Check if we're not the default SMS app if (!Utils.isDefaultSmsApp(this)) { // Ask to become the default SMS app new DefaultSmsHelper(this, R.string.not_default_send) .showIfNotDefault((ViewGroup) getWindow().getDecorView().getRootView()); } else if (mComposeFragment != null && !mComposeFragment.isReplyTextEmpty() && mComposeFragment.getRecipientAddresses().length == 0) { // If there is Draft message and no recipients are set new QKDialog() .setContext(this) .setMessage(R.string.discard_message_reason) .setPositiveButton( R.string.yes, v -> { super.onBackPressed(); }) .setNegativeButton(R.string.cancel, null) .show(); } else { super.onBackPressed(); } }
private void handleComposeButtonClick() { switch (mButtonState) { case ATTACH: mAttachmentPanel.setVisibility(VISIBLE); updateButtonState(); break; case SEND: // If the API version is less than KitKat, they can send an SMS; so do this. if (Build.VERSION.SDK_INT < 19) { if (mDelayedMessagingEnabled) { sendDelayedSms(); } else { sendSms(); } } else { // Otherwise... check if we're not the default SMS app boolean isDefaultSmsApp = Utils.isDefaultSmsApp(mContext); // Now make sure that a client hasn't blocked sending, i.e. in the welcome // screen when we have a demo conversation. if (mIsSendingBlocked) { // Show the sending blocked message (if it exists) Toast.makeText(mContext, mSendingBlockedMessage, Toast.LENGTH_SHORT).show(); } else if (!isDefaultSmsApp) { // Ask to become the default SMS app new DefaultSmsHelper(mContext, R.string.not_default_send).showIfNotDefault(this); } else if (!TextUtils.isEmpty(mReplyText.getText()) || mAttachment.hasAttachment()) { if (mDelayedMessagingEnabled) { sendDelayedSms(); } else { sendSms(); } } } break; case CLOSE: mAttachmentPanel.setVisibility(GONE); updateButtonState(); break; case CANCEL: mSendingCancelled = true; mProgressAnimator.end(); // updateButtonState(); break; } }