Created
November 27, 2019 15:51
-
-
Save anka/b56d66dedce28de8c3c0c056d841f69b to your computer and use it in GitHub Desktop.
Android main activity implementing a Flutter method channel for file sharing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : FlutterActivity() { | |
private val SHARE_CHANNEL = "jademind.com/share" | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
GeneratedPluginRegistrant.registerWith(this) | |
MethodChannel(flutterView, SHARE_CHANNEL).setMethodCallHandler { call, result -> | |
if (call.method.equals("share-file")) { | |
val argsMap = call.arguments as HashMap<String, String> | |
val subject = argsMap.get("subject") | |
val filename = argsMap.get("filename") | |
val filepath = argsMap.get("filepath") | |
val mimeType = argsMap.get("mimeType") | |
val contentUri = Uri.parse(filepath) | |
val shareIntent = Intent(Intent.ACTION_SEND) | |
shareIntent.setType(mimeType) | |
shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri) | |
this.startActivity(Intent.createChooser(shareIntent, subject)) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment