IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Impossible d'envoyer un mail avec pièce jointe Kotlin


Sujet :

Android

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Directeur de projet
    Inscrit en
    Décembre 2022
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Directeur de projet
    Secteur : Services à domicile

    Informations forums :
    Inscription : Décembre 2022
    Messages : 2
    Points : 1
    Points
    1
    Par défaut Impossible d'envoyer un mail avec pièce jointe Kotlin
    Bonjour à tous,
    Je développe actuellement une appli et je souhaite envoyer un mail avec PJ.
    Tout fonctionne la PJ apparaît bien au moment de choisir le client mail MAIS
    sauf qu'après avoir choisi Yahoomail par exemple: au moment où le mail se génère, la pièce jointe ne se joint pas.
    J'ai un message d'erreur du client mail qui me dit la pièce jointe est introuvable ou supprimée (Yahoo Mail)
    Je pense qu'il s'agit de l'URi qui est erronée??? ou du typage de l'intent ????
    Voici mon code:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
     
    package com.example.crimeaidecompose.ui.component
     
    import android.content.Intent
    import android.net.Uri
    import android.os.Build
    import androidx.annotation.RequiresApi
    import androidx.compose.foundation.layout.*
    import androidx.compose.material.Button
    import androidx.compose.material.Text
    import androidx.compose.material.TextField
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.mutableStateOf
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Alignment
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.graphics.Color
    import androidx.compose.ui.platform.LocalContext
    import androidx.compose.ui.text.TextStyle
    import androidx.compose.ui.text.input.TextFieldValue
    import androidx.compose.ui.unit.dp
    import androidx.compose.ui.unit.sp
    import androidx.navigation.NavController
     
    @RequiresApi(Build.VERSION_CODES.R)
    @Composable
    fun OpenEmailer(navController: NavController) {
     
        // in the below line, we are
        // creating variables for URL
        val senderEmail = remember {
            mutableStateOf(TextFieldValue())
        }
        val emailSubject = remember {
            mutableStateOf(TextFieldValue())
        }
        val emailBody = remember {
            mutableStateOf(TextFieldValue())
        }
     
        // on below line we are creating
        // a variable for a context
        val ctx = LocalContext.current
     
        // on below line we are creating a column
        Column(
            // on below line we are specifying modifier
            // and setting max height and max width
            // for our column
            modifier = Modifier
                .fillMaxSize()
                .fillMaxHeight()
                .fillMaxWidth()
                // on below line we are
                // adding padding for our column
                .padding(5.dp),
            // on below line we are specifying horizontal
            // and vertical alignment for our column
            horizontalAlignment = Alignment.CenterHorizontally,
            verticalArrangement = Arrangement.Center
        ) {
     
            // on the below line, we are
            // creating a text field.
            TextField(
                // on below line we are specifying
                // value for our text field.
                value = senderEmail.value,
     
                // on below line we are adding on value
                // change for text field.
                onValueChange = { senderEmail.value = it },
     
                // on below line we are adding place holder as text
                placeholder = { Text(text = "Enter sender email address") },
     
                // on below line we are adding modifier to it
                // and adding padding to it and filling max width
                modifier = Modifier
                    .padding(16.dp)
                    .fillMaxWidth(),
     
                // on below line we are adding text style
                // specifying color and font size to it.
                textStyle = TextStyle(color = Color.Black, fontSize = 15.sp),
     
                // on below line we are
                // adding single line to it.
                singleLine = true,
            )
            // on below line adding a spacer.
            Spacer(modifier = Modifier.height(10.dp))
     
            // on the below line, we are creating a text field.
            TextField(
                // on below line we are specifying
                // value for our text field.
                value = emailSubject.value,
     
                // on below line we are adding on value change
                // for text field.
                onValueChange = { emailSubject.value = it },
     
                // on below line we are adding place holder as text
                placeholder = { Text(text = "Enter email subject") },
     
                // on below line we are adding modifier to it
                // and adding padding to it and filling max width
                modifier = Modifier
                    .padding(16.dp)
                    .fillMaxWidth(),
     
                // on below line we are adding text style
                // specifying color and font size to it.
                textStyle = TextStyle(color = Color.Black, fontSize = 15.sp),
     
                // on below line we are
                // adding single line to it.
                singleLine = true,
            )
     
            // on below line adding a spacer.
            Spacer(modifier = Modifier.height(10.dp))
     
            // on the below line, we are creating a text field.
            TextField(
                // on below line we are specifying
                // value for our text field.
                value = emailBody.value,
     
                // on below line we are adding on value
                // change for text field.
                onValueChange = { emailBody.value = it },
     
                // on below line we are adding place holder as text
                placeholder = { Text(text = "Enter email body") },
     
                // on below line we are adding modifier to it
                // and adding padding to it and filling max width
                modifier = Modifier
                    .padding(16.dp)
                    .fillMaxWidth(),
     
                // on below line we are adding text style
                // specifying color and font size to it.
                textStyle = TextStyle(color = Color.Black, fontSize = 15.sp),
     
                // on below line we are
                // adding single line to it.
                singleLine = true,
            )
     
            // on below line adding a spacer.
            Spacer(modifier = Modifier.height(20.dp))
     
            // on below line adding a
            // button to send an email
            Button(onClick = {
     
                // on below line we are creating
                // an intent to send an email
                val i = Intent(Intent.ACTION_SEND)
                // on below line we are passing email address,
                // email subject and email body
                val emailAddress = arrayOf(senderEmail.value.text)
                i.putExtra(Intent.EXTRA_EMAIL,emailAddress)
                i.putExtra(Intent.EXTRA_SUBJECT,emailSubject.value.text)
                i.putExtra(Intent.EXTRA_TEXT,emailBody.value.text)
                //the problem occurs here the mail app notify "sorry we're unable to find the attached file"
                i.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.ressource://com.example.crimeaidecompose.ui/res/drawable/seringue.png"))
     
     
                // on below line we are
                // setting type of intent
                i.type = "message/rfc822"
     
                // on the below line we are starting our activity to open email application.
                ctx.startActivity(Intent.createChooser(i,"Choose an Email client : "))
     
            }) {
                // on the below line creating a text for our button.
                Text(
                    // on below line adding a text ,
                    // padding, color and font size.
                    text = "Send Email",
                    modifier = Modifier.padding(10.dp),
                    color = Color.White,
                    fontSize = 15.sp
                )
            }
        }
    }
    merci pour votre retour

  2. #2
    Nouveau Candidat au Club
    Homme Profil pro
    Directeur de projet
    Inscrit en
    Décembre 2022
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Directeur de projet
    Secteur : Services à domicile

    Informations forums :
    Inscription : Décembre 2022
    Messages : 2
    Points : 1
    Points
    1
    Par défaut toujours pas d'idées
    bonjour, personne pour un coup de main!!!!!!

Discussions similaires

  1. Envoyer un MAIL avec pièce jointe
    Par DevPerl dans le forum Modules
    Réponses: 3
    Dernier message: 07/09/2007, 23h34
  2. Comment envoyer un mail avec pièce jointe (BCB6)
    Par renesouley dans le forum C++Builder
    Réponses: 16
    Dernier message: 30/12/2006, 21h56
  3. Envoyer un mail avec pièce jointe
    Par anirose dans le forum VBA Access
    Réponses: 6
    Dernier message: 08/11/2006, 12h45
  4. Envoyer un mail avec pièce jointe (javascript)
    Par Dorra_26 dans le forum Général JavaScript
    Réponses: 15
    Dernier message: 21/07/2006, 08h31
  5. [C++/MFC]Envoyer un mail avec Pièce jointe
    Par cjacquel dans le forum MFC
    Réponses: 4
    Dernier message: 12/06/2006, 13h48

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo