ÇA ENVOOOOOOOOOOIIIIIIIIIIIIE!!!!!!!!!!
This commit is contained in:
parent
b71eb56d1a
commit
e9b8e5020f
|
@ -117,6 +117,11 @@
|
|||
android:parentActivityName=".MainActivity"/>
|
||||
|
||||
<activity android:name=".ui_components.NornCaptureActivity" />
|
||||
|
||||
<provider
|
||||
android:grantUriPermissions="true"
|
||||
android:authorities="xyz.johnny.norntalk.messages.NornMMSFileProvider"
|
||||
android:name="xyz.johnny.norntalk.messages.NornMMSFileProvider" />
|
||||
|
||||
</application>
|
||||
|
||||
|
|
|
@ -5,8 +5,6 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import com.klinker.android.send_message.MmsSentReceiver.EXTRA_FILE_PATH
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Classe recevant les MMS.
|
||||
|
@ -16,9 +14,6 @@ class NornMMSReceiver: BroadcastReceiver() {
|
|||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
Log.d(this::class.java.simpleName, "MMS received")
|
||||
Toast.makeText(context, "MMS received", Toast.LENGTH_LONG).show()
|
||||
|
||||
val filePath = intent?.getStringExtra(EXTRA_FILE_PATH)
|
||||
File(filePath).delete()
|
||||
}
|
||||
|
||||
}
|
|
@ -5,7 +5,9 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import com.klinker.android.send_message.MmsSentReceiver
|
||||
import xyz.johnny.norntalk.R
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Classe permettant d'avertir de l'envoi d'un MMS
|
||||
|
@ -15,6 +17,9 @@ class NornMMSSentReceiver : BroadcastReceiver() {
|
|||
override fun onReceive(context: Context, intent: Intent?) {
|
||||
Log.d(this::class.java.simpleName, "MMS sent")
|
||||
Toast.makeText(context, context.getString(R.string.message_sent), Toast.LENGTH_LONG).show()
|
||||
|
||||
val filePath = intent?.getStringExtra(MmsSentReceiver.EXTRA_FILE_PATH)
|
||||
File(filePath).delete()
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,10 @@
|
|||
package xyz.johnny.norntalk.messages
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.net.Uri
|
||||
import com.klinker.android.send_message.Message
|
||||
import xyz.johnny.norntalk.database.NornDatabase
|
||||
import xyz.johnny.norntalk.database.entities.Media
|
||||
import xyz.johnny.norntalk.security.Curve
|
||||
|
@ -15,6 +18,13 @@ import java.io.FileInputStream
|
|||
class NornMedia private constructor(context: Context, val mimeType: String) {
|
||||
|
||||
private var _data: ByteArray? = null
|
||||
val bitmap by lazy {
|
||||
if (this.uri != null)
|
||||
this.getBitmap(context)
|
||||
else
|
||||
null
|
||||
|
||||
}
|
||||
private var uri: Uri? = null
|
||||
private var _name: String = "media_" + System.currentTimeMillis()
|
||||
val name get() = _name
|
||||
|
@ -29,7 +39,7 @@ class NornMedia private constructor(context: Context, val mimeType: String) {
|
|||
}
|
||||
|
||||
private val data: ByteArray by lazy {
|
||||
this._data ?: readFileFromUri(context, this.uri!!)
|
||||
this._data ?: Message.bitmapToByteArray(this.bitmap)
|
||||
}
|
||||
|
||||
private fun readFileFromUri(context: Context, uri: Uri): ByteArray {
|
||||
|
@ -44,6 +54,13 @@ class NornMedia private constructor(context: Context, val mimeType: String) {
|
|||
return data.toByteArray()
|
||||
}
|
||||
|
||||
private fun getBitmap(context: Context): Bitmap {
|
||||
context.contentResolver.openFileDescriptor(uri, "r").use { parcelFileDescriptor ->
|
||||
val fileDescriptor = parcelFileDescriptor.getFileDescriptor()
|
||||
return BitmapFactory.decodeFileDescriptor(fileDescriptor)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
|
||||
|
|
|
@ -452,62 +452,50 @@ class NornTransaction constructor(private val context: Context) {
|
|||
|
||||
private fun sendMmsThroughSystem(context: Context, subject: String, parts: List<MMSPart>,
|
||||
addresses: Array<String>, explicitSentMmsReceiver: Intent?) {
|
||||
val fileName = "send." + Math.abs(Random().nextLong()).toString() + ".dat"
|
||||
val mSendFile = File(context.cacheDir, fileName)
|
||||
|
||||
val sendReq = buildPdu(context, addresses, subject, parts)
|
||||
|
||||
val intent = Intent(context, NornMMSSentReceiver::class.java)
|
||||
|
||||
intent.putExtra(MmsSentReceiver.EXTRA_FILE_PATH, mSendFile.path)
|
||||
val pendingIntent = PendingIntent.getBroadcast(
|
||||
context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT)
|
||||
|
||||
val writerUri = Uri.Builder()
|
||||
.authority("xyz.johnny.norntalk.messages.NornMMSFileProvider")
|
||||
.path(fileName)
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.build()
|
||||
var contentUri: Uri? = null
|
||||
|
||||
val data = PduComposer(context, sendReq).make()
|
||||
|
||||
try {
|
||||
val fileName = "send." + Math.abs(Random().nextLong()).toString() + ".dat"
|
||||
val mSendFile = File(context.cacheDir, fileName)
|
||||
|
||||
val sendReq = buildPdu(context, addresses, subject, parts)
|
||||
|
||||
val intent: Intent
|
||||
if (explicitSentMmsReceiver == null) {
|
||||
intent = Intent(MmsSentReceiver.MMS_SENT)
|
||||
BroadcastUtils.addClassName(context, intent, MmsSentReceiver.MMS_SENT)
|
||||
} else {
|
||||
intent = explicitSentMmsReceiver
|
||||
FileOutputStream(mSendFile).use { writer ->
|
||||
writer.write(data)
|
||||
}
|
||||
contentUri = writerUri
|
||||
} catch (e: IOException) {
|
||||
Log.e(TAG, "Error writing send file", e)
|
||||
}
|
||||
|
||||
intent.putExtra(MmsSentReceiver.EXTRA_FILE_PATH, mSendFile.path)
|
||||
val pendingIntent = PendingIntent.getBroadcast(
|
||||
context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT)
|
||||
val configOverrides = Bundle()
|
||||
configOverrides.putBoolean(SmsManager.MMS_CONFIG_GROUP_MMS_ENABLED, settings.group)
|
||||
val httpParams = MmsConfig.getHttpParams()
|
||||
if (!TextUtils.isEmpty(httpParams)) {
|
||||
configOverrides.putString(SmsManager.MMS_CONFIG_HTTP_PARAMS, httpParams)
|
||||
}
|
||||
configOverrides.putInt(SmsManager.MMS_CONFIG_MAX_MESSAGE_SIZE, MmsConfig.getMaxMessageSize())
|
||||
|
||||
val writerUri = Uri.Builder()
|
||||
.authority("xyz.johnny.norntalk.messages.NornMMSFileProvider")
|
||||
.path(fileName)
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.build()
|
||||
var contentUri: Uri? = null
|
||||
|
||||
try {
|
||||
FileOutputStream(mSendFile).use { writer ->
|
||||
writer.write(PduComposer(context, sendReq).make())
|
||||
}
|
||||
contentUri = writerUri
|
||||
} catch (e: IOException) {
|
||||
Log.e(TAG, "Error writing send file", e)
|
||||
}
|
||||
|
||||
val configOverrides = Bundle()
|
||||
configOverrides.putBoolean(SmsManager.MMS_CONFIG_GROUP_MMS_ENABLED, settings.group)
|
||||
val httpParams = MmsConfig.getHttpParams()
|
||||
if (!TextUtils.isEmpty(httpParams)) {
|
||||
configOverrides.putString(SmsManager.MMS_CONFIG_HTTP_PARAMS, httpParams)
|
||||
}
|
||||
configOverrides.putInt(SmsManager.MMS_CONFIG_MAX_MESSAGE_SIZE, MmsConfig.getMaxMessageSize())
|
||||
|
||||
if (contentUri != null) {
|
||||
SmsManagerFactory.createSmsManager(settings).sendMultimediaMessage(context,
|
||||
contentUri, null, configOverrides, pendingIntent)
|
||||
} else {
|
||||
Log.e(TAG, "Error writing sending Mms")
|
||||
try {
|
||||
pendingIntent.send(SmsManager.MMS_ERROR_IO_ERROR)
|
||||
} catch (ex: PendingIntent.CanceledException) {
|
||||
Log.e(TAG, "Mms pending intent cancelled?", ex)
|
||||
}
|
||||
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "error using system sending method", e)
|
||||
if (contentUri != null) {
|
||||
SmsManager.getDefault().sendMultimediaMessage(context,
|
||||
contentUri, null, configOverrides, pendingIntent)
|
||||
} else {
|
||||
Log.e(TAG, "Error writing sending Mms")
|
||||
println("aaajoai")
|
||||
pendingIntent.send(SmsManager.MMS_ERROR_IO_ERROR)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ class ComposeView: View {
|
|||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (requestCode == PICK_PICTURE_REQUEST && resultCode == Activity.RESULT_OK && data != null) {
|
||||
val uri = data.data
|
||||
val mimeType = this.contentResolver.getType(uri)
|
||||
val mimeType = "image/jpeg"
|
||||
this.medias.add(NornMedia(this, mimeType, uri))
|
||||
Toast.makeText(this, uri.toString(), Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue