-2

我有自己的自定义键盘,因此使用键盘的输入法,无论是来自我自己的应用程序还是来自第三方应用程序,我都可以从编辑文本中获取整个文本。一切正常运行都需要所有 Microsoft 应用程序。他们只为我提供有限的字符文本。那么我如何在 Ms 应用程序中实现这一点呢?这是我通过键盘获取文本的代码。

        ExtractedTextRequest extractedTextRequest = new ExtractedTextRequest();
        ExtractedText extractedText = getCurrentInputConnection().getExtractedText(extractedTextRequest, 0);

        wordReadAloud = ((String) extractedText.text);
        CharSequence textBeforeCursor = getCurrentInputConnection().getTextBeforeCursor(wordReadAloud.length(), 0);
4

3 回答 3

1

这个问题的一个简单答案是你做不到。如果该应用程序的开发人员不打算共享这些内容,Android 架构不允许您从另一个应用程序获取组件(字符串、图像、媒体等)。因此,创建自己的内容。

于 2021-03-24T06:10:49.753 回答
0

首先,您已在清单文件中设置要在哪个活动或第一个活动中获取数据

参考网址 - https://developer.android.com/training/sharing/receive

首先,我必须尝试这个例子,然后我必须与你分享代码,所以请在
完全理解之后投票,不要在没有你的测试的情况下得到错误的投票......

<intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="image/*" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="text/plain" />
        </intent-filter>

之后在活动中获取意图数据......

    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if ("text/plain".equals(type)) {
            handleSendText(intent); // Handle text being sent
        } else if (type.startsWith("image/")) {
            handleSendImage(intent); // Handle single image being sent
        }
    } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
        if (type.startsWith("image/")) {
          //  handleSendMultipleImages(intent); // Handle multiple images being sent
        }
    } else {
        // Handle other intents, such as being started from the home screen
    }

}


void handleSendText(Intent intent) {
    String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
    if (sharedText != null) {
        // Update UI to reflect text being shared
        Log.e("textData", "handleSendText: "+sharedText);
    }
}

void handleSendImage(Intent intent) {
    Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
    if (imageUri != null) {
        // Update UI to reflect image being shared
        Log.e("ImageData", "handleSendImage: "+imageUri);
    }
}
于 2021-03-22T10:50:21.760 回答
0

您可以使用这些代码发送请在解决您的问题后投票

        Intent sendIntent = new Intent(Intent.ACTION_SEND);
        sendIntent.setType("text/plain");
        sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
        Intent shareIntent = Intent.createChooser(sendIntent, "Your Post IS Ready to share");
        context.startActivity(shareIntent);
于 2021-03-20T06:50:47.240 回答