开发者

How to get html code from browser when share menu is selected

I'm trying to make an app that will display the url and page title that I am currently viewing in the browser when I choose the share menu and select my app.

This is my Intent filter in the manifest.xml:

intent-filter

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

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

data android:mimeType="text/plain" 

intent-filter

This is the code in my activity:

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

This code is working to get the url of the page, but I can't figure out how to get the title of the page I'm viewing in the browser. One way of doing this which I got working was to use HttpResponse to execute a new request and then get the page content and s开发者_StackOverflowearch through that to get the title. Is there an easier way to find out the title of the page?

Any help would be much appreciated. Thanks.


I think the title comes to you in the EXTRA_SUBJECT Intent extra.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜