【问题标题】:How to get html code from browser when share menu is selected选择共享菜单时如何从浏览器获取html代码
【发布时间】:2011-09-28 20:45:42
【问题描述】:

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

这是我在 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 执行新请求,然后获取页面内容并通过该内容进行搜索以获取标题。有没有更简单的方法来找出页面的标题?

任何帮助将不胜感激。谢谢。

【问题讨论】:

    标签: android android-intent browser android-manifest android-browser


    【解决方案1】:

    我认为标题是在 EXTRA_SUBJECT Intent 额外出现的。

    【讨论】:

    • 谢谢。我所要做的就是添加行 title = intent.getStringExtra(Intent.EXTRA_SUBJECT);
    猜你喜欢
    • 2016-06-23
    • 2011-03-14
    • 2018-12-10
    • 2013-09-29
    • 2012-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多