我想从第三方应用程序获取全文

时间:2021-02-26 06:32:23

标签: android android-textinputedittext inputconnection

我想从第三方应用程序获取全文,我正在使用以下代码来实现这一点。但是现在我遇到了 Ms word 应用程序的问题,在 Ms word 应用程序中,我没有得到整个文本。那么我如何在 Ms word 中实现这一点?

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

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

3 个答案:

答案 0 :(得分: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);

答案 1 :(得分: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);
    }
}

答案 2 :(得分:0)

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

相关问题