I have a TextView in an AppWidget where the text is set by a user.
This text can include one or more URL links (i.e http:/
www.google.com). I want these URLs to be clickable and open the
browser and go to whatever link was clicked. I have accomlished this
partially.The code I have at this point is as follows:

Intent clickIntent = new Intent();
clickIntent.setAction(Intent.ACTION_VIEW);
clickIntent.setData(Uri.parse(textViewContent.toString()));
clickIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

PendingIntent pendingIntentClick = PendingIntent.getActivity(context,
0, clickIntent, Intent.FLAG_ACTIVITY_NEW_TASK);

views.setOnClickPendingIntent(R.id.widget_textview,
pendingIntentClick);


This code will open the browser and go to the correct URL if the
content of the TextView contains only one link and no other links or
text of any kind. This is because setData uses everything in the
TextView as the URI.

So, how would I go about having a method to tell if what was clicked
is a link and which link it is if there are multiple links etc?
Basically, I need the browser to open to the correct link that is
clicked.


Also, I have tried to go about this a different way. I tried using the
XML property, android:autoLink="web", on the TextView of the
AppWidget. This of course makes the URLs look like links and makes
them clickable but an error occurs when a link is clicked. This error
is as follows:

"android.util.AndroidRuntimeException: Calling startActivity() from
outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK
flag. Is this really what you want?"

Using android:autoLink="web", the browser activity tries to start
without any additional code (meaning the browser activity tries to
start without the clickIntent code above). So, I do not know where I
would add a FLAG_ACTIVITY_NEW_TASK in this case. Is there something I
can do in the manifest.xml or another XML file?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to