handle textview link click in my android app

前端 未结 12 1095
迷失自我
迷失自我 2020-11-22 04:33

I\'m currently rendering HTML input in a TextView like so:

tv.setText(Html.fromHtml(\"test\"));

The HTML b

12条回答
  •  情话喂你
    2020-11-22 04:50

    Coming at this almost a year later, there's a different manner in which I solved my particular problem. Since I wanted the link to be handled by my own app, there is a solution that is a bit simpler.

    Besides the default intent filter, I simply let my target activity listen to ACTION_VIEW intents, and specifically, those with the scheme com.package.name

    
        
        
          
    
    

    This means that links starting with com.package.name:// will be handled by my activity.

    So all I have to do is construct a URL that contains the information I want to convey:

    com.package.name://action-to-perform/id-that-might-be-needed/
    

    In my target activity, I can retrieve this address:

    Uri data = getIntent().getData();
    

    In my example, I could simply check data for null values, because when ever it isn't null, I'll know it was invoked by means of such a link. From there, I extract the instructions I need from the url to be able to display the appropriate data.

提交回复
热议问题