2

我正在尝试制作一个应用程序,当我选择共享菜单并选择我的应用程序时,它将显示我当前在浏览器中查看的 url 和页面标题。

这是 manifest.xml 中的 Intent 过滤器:

intent-filter

action android:name="android.intent.action.SEND"

category android:name="android.intent.category.DEFAULT" 

data android:mimeType="text/plain" 

intent-filter

这是我活动中的代码:

public void onCreate(Bundle savedInstanceState) {    
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    TextView text = (TextView) this.findViewById(R.id.url_text);
    Intent intent = getIntent();
    if (savedInstanceState == null && intent != null) {
        Log.d(TAG, "intent != null");
        if (intent.getAction().equals(Intent.ACTION_SEND)) {
            Log.d(TAG, "intent.getAction().equals(Intent.ACTION_SEND)");
            url = intent.getStringExtra(Intent.EXTRA_TEXT);
            text.setText(url);          
        }
    }
}
}

此代码正在获取页面的 url,但我无法弄清楚如何获取我在浏览器中查看的页面的标题。我开始使用的一种方法是使用 HttpResponse 执行新请求,然后获取页面内容并通过该内容进行搜索以获取标题。有没有更简单的方法来找出页面的标题?

任何帮助将非常感激。谢谢。

4

1 回答 1

2

我认为这个标题是EXTRA_SUBJECT Intent额外给你的。

于 2011-07-05T15:06:45.813 回答