views:

28

answers:

1

I am trying to load BROWSER VIEW intent in android within onTouchEvent. Basically i have create a live wallpaper and if i click on it then i want to open BROWSER VIEW intent with a specified uri.

i have tried following code inside onTouchEvent

Uri uri = Uri.parse("http://www.google.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

but i am getting following error

I am trying to load BROWSER VIEW intent in android within onTouchEvent. Basically i have create a live wallpaper and if i click on it then i want to open BROWSER VIEW intent with a specified uri.

i have tried following code inside onTouchEvent

Uri uri = Uri.parse("http://www.google.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

but i am getting following error

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

another apporch is that i have create one activity and inside its onCreate function i tried following code

public void onCreate(Bundle icicle) {
super.onCreate(icicle);

browser=new WebView(this);
setContentView(browser);
browser.loadUrl("http://commonsware.com");
}

and tried to load this activity via custom intent message as follows , but still i am getting the same error

Intent intent = new Intent(ACTION);
startActivity(intent);

// over here i have not used context as while creating live wallpaer i don't know here to get
// the   context
A: 

I have solved this problem on my own by writing following code.

                 Intent intent = new Intent(Intent.ACTION_VIEW);                     
                 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                 intent.setData(android.net.Uri.parse("http://www.gmail.com"));
                 startActivity(intent);
Hunt