-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Paste images from your clipboard in android (#461)
- Loading branch information
1 parent
6e1f072
commit df46f31
Showing
8 changed files
with
153 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,48 @@ | ||
package com.apps.blt | ||
|
||
import android.content.ClipData | ||
import android.content.ClipboardManager | ||
import android.graphics.Bitmap | ||
import android.graphics.drawable.BitmapDrawable | ||
import android.os.Build | ||
import android.provider.MediaStore | ||
import android.util.Base64 | ||
import androidx.annotation.NonNull | ||
import androidx.annotation.RequiresApi | ||
import io.flutter.embedding.android.FlutterActivity | ||
import io.flutter.embedding.engine.FlutterEngine | ||
import io.flutter.plugin.common.MethodChannel | ||
import java.io.ByteArrayOutputStream | ||
|
||
class MainActivity: FlutterActivity() { | ||
class MainActivity : FlutterActivity() { | ||
private val CHANNEL = "clipboard_image_channel" | ||
|
||
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { | ||
super.configureFlutterEngine(flutterEngine) | ||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result -> | ||
if (call.method == "getClipboardImage") { | ||
val clipboard = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager | ||
val clipData = clipboard.primaryClip | ||
|
||
if (clipData != null && clipData.itemCount > 0) { | ||
val item = clipData.getItemAt(0) | ||
|
||
if (item.uri != null) { | ||
val bitmap = MediaStore.Images.Media.getBitmap(contentResolver, item.uri) | ||
val stream = ByteArrayOutputStream() | ||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream) | ||
val byteArray = stream.toByteArray() | ||
val base64String = Base64.encodeToString(byteArray, Base64.DEFAULT) | ||
result.success(base64String) | ||
} else { | ||
result.error("NO_IMAGE", "Clipboard does not contain an image", null) | ||
} | ||
} else { | ||
result.error("EMPTY_CLIPBOARD", "Clipboard is empty", null) | ||
} | ||
} else { | ||
result.notImplemented() | ||
} | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
org.gradle.jvmargs=-Xmx1536M | ||
android.useAndroidX=true | ||
android.enableJetifier=true | ||
android.enableJetifier=true |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Fri Jun 23 08:50:38 CEST 2017 | ||
#Tue Oct 29 01:30:50 IST 2024 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip |
This file contains 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
This file contains 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