Skip to content
This repository was archived by the owner on Jan 30, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .fvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"flutter": "3.35.3"
}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ build/
open_mail_app.iml

# Ignore for libs
pubspec.lock
pubspec.lock

# FVM Version Cache
.fvm/
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dart.flutterSdkPath": ".fvm/versions/3.35.3"
}
19 changes: 14 additions & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ group 'com.homex.open_mail_app'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '2.2.10'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.android.tools.build:gradle:8.13.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -25,13 +25,22 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 31
compileSdk 36

compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = '17'
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
minSdkVersion 16
minSdkVersion 24
}
lintOptions {
disable 'InvalidPackage'
Expand All @@ -40,5 +49,5 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.google.code.gson:gson:2.13.2'
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.homex.open_mail_app

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.content.pm.LabeledIntent
import android.net.Uri
import androidx.annotation.NonNull
import com.google.gson.Gson
import com.google.gson.annotations.SerializedName

Expand All @@ -13,44 +13,24 @@ import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.PluginRegistry.Registrar

class OpenMailAppPlugin : FlutterPlugin, MethodCallHandler {
private lateinit var channel: MethodChannel
private lateinit var applicationContext: Context

override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
// Although getFlutterEngine is deprecated we still need to use it for
// apps not updated to Flutter Android v2 embedding
channel = MethodChannel(flutterPluginBinding.flutterEngine.dartExecutor, "open_mail_app")
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "open_mail_app")
channel.setMethodCallHandler(this)
init(flutterPluginBinding.applicationContext)
}

// This static function is optional and equivalent to onAttachedToEngine. It supports the old
// pre-Flutter-1.12 Android projects. You are encouraged to continue supporting
// plugin registration via this function while apps migrate to use the new Android APIs
// post-flutter-1.12 via https://flutter.dev/go/android-project-migration.
//
// It is encouraged to share logic between onAttachedToEngine and registerWith to keep
// them functionally equivalent. Only one of onAttachedToEngine or registerWith will be called
// depending on the user's project. onAttachedToEngine or registerWith must both be defined
// in the same class.
companion object {
@JvmStatic
fun registerWith(registrar: Registrar) {
val channel = MethodChannel(registrar.messenger(), "open_mail_app")
val plugin = OpenMailAppPlugin()
channel.setMethodCallHandler(plugin)
plugin.init(registrar.context())
}
}

fun init(context: Context) {
private fun init(context: Context) {
applicationContext = context
}

override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
override fun onMethodCall(call: MethodCall, result: Result) {
if (call.method == "openMailApp") {
val opened = emailAppIntent(call.argument("nativePickerTitle") ?: "")
result.success(opened)
Expand All @@ -72,11 +52,11 @@ class OpenMailAppPlugin : FlutterPlugin, MethodCallHandler {
}
}

override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}

private fun emailAppIntent(@NonNull chooserTitle: String): Boolean {
private fun emailAppIntent(chooserTitle: String): Boolean {
val emailIntent = Intent(Intent.ACTION_VIEW, Uri.parse("mailto:"))
val packageManager = applicationContext.packageManager

Expand Down Expand Up @@ -113,7 +93,8 @@ class OpenMailAppPlugin : FlutterPlugin, MethodCallHandler {
}
}

private fun composeNewEmailAppIntent(@NonNull chooserTitle: String, @NonNull contentJson: String): Boolean {
@SuppressLint("IntentReset")
private fun composeNewEmailAppIntent(chooserTitle: String, contentJson: String): Boolean {
val packageManager = applicationContext.packageManager
val emailContent = Gson().fromJson(contentJson, EmailContent::class.java)
val emailIntent = Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"))
Expand All @@ -136,23 +117,24 @@ class OpenMailAppPlugin : FlutterPlugin, MethodCallHandler {
for (i in 1 until activitiesHandlingEmails.size) {
val activityHandlingEmail = activitiesHandlingEmails[i]
val packageName = activityHandlingEmail.activityInfo.packageName
emailComposingIntents.add(
LabeledIntent(
Intent(Intent.ACTION_SENDTO).apply {
data = Uri.parse("mailto:")
type = "text/plain"
setClassName(activityHandlingEmail.activityInfo.packageName, activityHandlingEmail.activityInfo.name)
putExtra(Intent.EXTRA_EMAIL, emailContent.to.toTypedArray())
putExtra(Intent.EXTRA_CC, emailContent.cc.toTypedArray())
putExtra(Intent.EXTRA_BCC, emailContent.bcc.toTypedArray())
putExtra(Intent.EXTRA_SUBJECT, emailContent.subject)
putExtra(Intent.EXTRA_TEXT, emailContent.body)
},
packageName,
activityHandlingEmail.loadLabel(packageManager),
activityHandlingEmail.icon
)

emailComposingIntents.add(
LabeledIntent(
Intent(Intent.ACTION_SENDTO).apply {
data = Uri.parse("mailto:")
type = "text/plain"
setClassName(activityHandlingEmail.activityInfo.packageName, activityHandlingEmail.activityInfo.name)
putExtra(Intent.EXTRA_EMAIL, emailContent.to.toTypedArray())
putExtra(Intent.EXTRA_CC, emailContent.cc.toTypedArray())
putExtra(Intent.EXTRA_BCC, emailContent.bcc.toTypedArray())
putExtra(Intent.EXTRA_SUBJECT, emailContent.subject)
putExtra(Intent.EXTRA_TEXT, emailContent.body)
},
packageName,
activityHandlingEmail.loadLabel(packageManager),
activityHandlingEmail.icon
)
)
}

val extraEmailComposingIntents = emailComposingIntents.toTypedArray()
Expand Down Expand Up @@ -183,7 +165,8 @@ class OpenMailAppPlugin : FlutterPlugin, MethodCallHandler {
return true
}

private fun composeNewEmailInSpecificEmailAppIntent(@NonNull name: String, @NonNull contentJson: String): Boolean {
@SuppressLint("IntentReset")
private fun composeNewEmailInSpecificEmailAppIntent(name: String, contentJson: String): Boolean {
val packageManager = applicationContext.packageManager
val emailContent = Gson().fromJson(contentJson, EmailContent::class.java)
val emailIntent = Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"))
Expand Down
30 changes: 13 additions & 17 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
Expand All @@ -6,10 +12,6 @@ if (localPropertiesFile.exists()) {
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
Expand All @@ -21,16 +23,12 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion flutter.compileSdkVersion

ndkVersion = "27.0.12077973"
compileSdkVersion 36
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

kotlinOptions {
Expand All @@ -44,8 +42,8 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.homex.open_mail_app_example"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
minSdkVersion 21
targetSdkVersion 36
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand All @@ -57,12 +55,10 @@ android {
signingConfig signingConfigs.debug
}
}
namespace 'com.homex.open_mail_app_example'
}

flutter {
source '../..'
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
3 changes: 1 addition & 2 deletions example/android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.homex.open_mail_app_example">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
Expand Down
3 changes: 1 addition & 2 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.homex.open_mail_app_example">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:name="${applicationName}"
android:label="open_mail_app_example"
Expand Down
3 changes: 1 addition & 2 deletions example/android/app/src/profile/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.homex.open_mail_app_example">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
Expand Down
28 changes: 13 additions & 15 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
google()
mavenCentral()
}
subprojects {
afterEvaluate { project ->
if (project.hasProperty('android')) {
project.android {
if (namespace == null) {
namespace project.group
}
}
}
}
}
}

rootProject.buildDir = '../build'
Expand All @@ -26,6 +24,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
}
3 changes: 3 additions & 0 deletions example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
5 changes: 2 additions & 3 deletions example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
zipStorePath=wrapper/dists
30 changes: 22 additions & 8 deletions example/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
include ':app'
pluginManagement {
def flutterSdkPath = {
def properties = new Properties()
file("local.properties").withInputStream { properties.load(it) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
return flutterSdkPath
}()

def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}

def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version '8.13.0' apply false
id "org.jetbrains.kotlin.android" version "1.9.21" apply false
}

include ":app"
Loading