Intercept copy to clipboard on chromeos and inject our file contents into the clipboard
This commit is contained in:
parent
eb6ac79eed
commit
0fd4d8d7fc
|
@ -31,6 +31,7 @@
|
|||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<receiver android:name=".ShareReceiver" android:exported="false"/>
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.provider"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.defined.mobile_nebula
|
||||
|
||||
import android.content.Intent
|
||||
import android.app.PendingIntent
|
||||
import android.content.*
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.pm.ResolveInfo
|
||||
import android.util.Log
|
||||
|
@ -85,16 +86,17 @@ class Share {
|
|||
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
intent.action = Intent.ACTION_SEND
|
||||
intent.type = "text/plain"
|
||||
intent.type = "text/*"
|
||||
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, title)
|
||||
intent.putExtra(Intent.EXTRA_STREAM, fileUri)
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
|
||||
val chooserIntent = Intent.createChooser(intent, title)
|
||||
chooserIntent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
chooserIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
val receiver = Intent(context, ShareReceiver::class.java)
|
||||
receiver.putExtra(Intent.EXTRA_TEXT, file)
|
||||
val pendingIntent = PendingIntent.getBroadcast(context, 0, receiver, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
|
||||
val chooserIntent = Intent.createChooser(intent, title, pendingIntent.intentSender)
|
||||
val resInfoList: List<ResolveInfo> = context.packageManager.queryIntentActivities(chooserIntent, PackageManager.MATCH_DEFAULT_ONLY)
|
||||
for (resolveInfo in resInfoList) {
|
||||
val packageName: String = resolveInfo.activityInfo.packageName
|
||||
|
@ -112,3 +114,21 @@ class Share {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ShareReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
if (intent == null) {
|
||||
return
|
||||
}
|
||||
|
||||
val res = intent.extras.get(Intent.EXTRA_CHOSEN_COMPONENT) as? ComponentName ?: return
|
||||
when (res.className) {
|
||||
"org.chromium.arc.intent_helper.SendTextToClipboardActivity" -> {
|
||||
val file = intent.extras[Intent.EXTRA_TEXT] as? File ?: return
|
||||
val clipboard = context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
|
||||
clipboard.primaryClip = ClipData.newPlainText("", file.readText())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue