【问题标题】:I want to get whole text from third party app我想从第三方应用程序获取全文
【发布时间】:2021-05-28 13:22:56
【问题描述】:

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

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

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

【问题讨论】:

  • 没有死,但是如果您只提供了 4 行代码,我们如何帮助您?您如何“从 3rd 方应用程序获取文本”?使用 AccessibilityService?使用 Xposed 模块(需要 Root 权限)?还有很多其他问题......你只是写了“我不能做X,请帮忙”之类的东西而不提供任何东西......

标签: android android-textinputedittext inputconnection


【解决方案1】:

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

【讨论】:

  • 但是我从其他应用程序获得了全文,除了所有 ms 的应用程序。我有自己的自定义键盘,所以我可以使用上面的代码获取文本。只是Ms的应用程序有问题。他们给了我们一些有限的文字。
【解决方案2】:

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

        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);

【讨论】:

  • 我想从其他应用获取全文
  • 你能给我一个简单的演示,我可以在看过演示后建议你
  • 嘿 @PravinSuthar 您的问题已使用今天的共享代码解决,请完成您的任务
【解决方案3】:

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

参考网址 - 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);
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-12
    • 1970-01-01
    • 2019-02-09
    • 1970-01-01
    相关资源
    最近更新 更多