Question

I am trying to load BROWSER VIEW intent in android within onTouchEvent. Basically I have created 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 the 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 approach is that I have create one activity and inside its onCreate method 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 wallpaper I
// don't know here to get the context
Was it helpful?

Solution

I have solved the problem on my own with the 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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top