Vérifier le numéro de téléphone que si NornTalk est l'app SMS par défaut
This commit is contained in:
parent
aaa53500a2
commit
bb9f87be5c
|
@ -5,7 +5,6 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.os.AsyncTask
|
||||
import android.provider.Telephony
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
|
@ -46,13 +45,6 @@ class MainActivity : BaseActivity() {
|
|||
}
|
||||
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)
|
||||
|
||||
// demander de définir Norn Talk comme application SMS par défaut
|
||||
if (Telephony.Sms.getDefaultSmsPackage(applicationContext) != applicationContext.packageName) {
|
||||
val intent = Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT)
|
||||
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, applicationContext.packageName)
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,7 +12,6 @@ import android.support.v7.app.AppCompatActivity
|
|||
import com.google.zxing.BarcodeFormat
|
||||
import xyz.johnny.norntalk.database.NornDatabase
|
||||
import xyz.johnny.norntalk.messages.NornNotification
|
||||
import xyz.johnny.norntalk.security.QRCode
|
||||
import xyz.johnny.norntalk.security.Security
|
||||
|
||||
|
||||
|
@ -23,6 +22,23 @@ import xyz.johnny.norntalk.security.Security
|
|||
*/
|
||||
class SplashActivity : AppCompatActivity() {
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Méthode permettant d'effectuer des opérations en parallèle
|
||||
*
|
||||
* @param function Fonction contenant l'opération à effectuer en parallèle
|
||||
* @return Tâche correspondant à l'opération
|
||||
*/
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
fun load_helper(function: () -> Any?): AsyncTask<Void, Void, Unit> {
|
||||
return object : AsyncTask<Void, Void, Unit>() {
|
||||
override fun doInBackground(vararg params: Void?) {
|
||||
function()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var _tasks: Array<AsyncTask<Void, Void, Unit>>? = null
|
||||
/**
|
||||
* Les tâches effectuées en arrière plan
|
||||
|
@ -51,21 +67,6 @@ class SplashActivity : AppCompatActivity() {
|
|||
fun checkperm(perm: String) = ContextCompat.checkSelfPermission(this, perm) != PackageManager.PERMISSION_GRANTED
|
||||
|
||||
|
||||
/**
|
||||
* Méthode permettant d'effectuer des opérations en parallèle
|
||||
*
|
||||
* @param function Fonction contenant l'opération à effectuer en parallèle
|
||||
* @return Tâche correspondant à l'opération
|
||||
*/
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private fun load_helper(function: () -> Any?): AsyncTask<Void, Void, Unit> {
|
||||
return object : AsyncTask<Void, Void, Unit>() {
|
||||
override fun doInBackground(vararg params: Void?) {
|
||||
function()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Charger l'ensemble des singletons de Security
|
||||
*
|
||||
|
@ -77,7 +78,6 @@ class SplashActivity : AppCompatActivity() {
|
|||
load_helper { Security.curve },
|
||||
load_helper { NornNotification.createChannel(this) },
|
||||
load_helper { NornDatabase.getNornDatabase(this) },
|
||||
load_helper { QRCode.getNumber(this, true) },
|
||||
load_helper { Security.barcodeEncoder.encodeBitmap("a", BarcodeFormat.QR_CODE, 512, 512).recycle() }
|
||||
)
|
||||
|
||||
|
|
|
@ -2,9 +2,11 @@ package xyz.johnny.norntalk.ui_components
|
|||
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.preference.PreferenceManager
|
||||
import android.provider.Telephony
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.view.WindowManager
|
||||
|
@ -14,6 +16,8 @@ import android.widget.Toast
|
|||
import kotlinx.android.synthetic.main.passalert_layout.*
|
||||
import org.bouncycastle.util.encoders.Hex
|
||||
import xyz.johnny.norntalk.R
|
||||
import xyz.johnny.norntalk.SplashActivity
|
||||
import xyz.johnny.norntalk.security.QRCode
|
||||
import xyz.johnny.norntalk.security.Security
|
||||
import java.security.MessageDigest
|
||||
|
||||
|
@ -70,6 +74,16 @@ abstract class BaseActivity: AppCompatActivity() {
|
|||
*/
|
||||
open fun initialize() {}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
// demander de définir Norn Talk comme application SMS par défaut
|
||||
if (Telephony.Sms.getDefaultSmsPackage(applicationContext) != applicationContext.packageName) {
|
||||
val intent = Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT)
|
||||
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, applicationContext.packageName)
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
// demander le mot de passe si l'utilisateur est sorti de l'application
|
||||
if (currentActivity == null && !NornCaptureActivity.scanning)
|
||||
|
@ -79,6 +93,9 @@ abstract class BaseActivity: AppCompatActivity() {
|
|||
// changer l'activité courante
|
||||
currentActivity = this
|
||||
|
||||
if (Telephony.Sms.getDefaultSmsPackage(applicationContext) == applicationContext.packageName)
|
||||
SplashActivity.load_helper { QRCode.getNumber(this, true) }
|
||||
|
||||
super.onResume()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue