0

我正在处理以下代码:

if (Intent.ACTION_SEND.equals(getIntent().getAction())) 
            {
                String text = getIntent().getStringExtra(Intent.EXTRA_TEXT);
                
                try
                {
                    Document doc = Jsoup.connect(text).get();
                    Log.i("DOC", doc.toString().toString());
                    Elements elementsHtml = doc.getElementsByTag("tr");  
                    ArrayList<String> temp1 = new ArrayList<String>();    
                    
                    for(Element element: elementsHtml)
                    {
    
                        temp1.add( element.text());
    
                    }
                    
                    //Add all the text to the edit text
                    for(int i=0;i<temp1.size();i++)
                    {
                        textField.append(temp1.get(i));
                    }
                    
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }
                
        
            }

此代码使用带有 Android 代码的 JSoup 库。我需要从网页中提取所有文本,这就是上面代码的目的。但相反,它所做的是获取网页的 URL 并将其附加到文本字段,仅此而已。

我需要所有的文字。此代码针对“tr”。

为什么会这样?我该如何纠正?

更新

我改变了我的代码如下,现在我什么也没得到!

 //Get the web page text if called from Share-Via
            if (Intent.ACTION_SEND.equals(getIntent().getAction())) 
            {
                String text = getIntent().getStringExtra(Intent.EXTRA_STREAM);
                
                try
                {
                    Document doc = Jsoup.connect(text).get();
                    Log.i("DOC", doc.toString().toString());
                    Elements elementsHtml = doc.getElementsByTag("tr");  
                    ArrayList<String> temp1 = new ArrayList<String>();    
                    
                    for(Element element: elementsHtml)
                    {
    
                        temp1.add( element.text());
    
                    }
                    
                    //Add all the text to the edit text
                    for(int i=0;i<temp1.size();i++)
                    {
                        textField.append(temp1.get(i));
                    }
                    
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }
                
        
            }

如果有帮助,这是我的清单文件代码(仅是必需的部分)

<activity
            android:name="com.xxx.xxx.xxx"
            android:screenOrientation="portrait"
            android:label="@string/app_name" >
            
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="text/plain"/>
                <data android:mimeType="image/*"/>
                <data android:mimeType="video/*"/>
            </intent-filter>
            
        </activity>
4

0 回答 0