3

Possible Duplicate:
How to restrict Android device to not open some specific site e.g.youtube, facebook

I am writing an application and a feature is that if the user opens youtube.com then not allow him to do this.

So I planned to kill the Android process if the user try to open it. I know that this code kills the process

android.os.Process.killProcess(pid);

but How can I get pid(process id) of process if it open youtube. The problem is to get process id which opens youtube.

Community
  • 1
  • 1
Azhar
  • 20,500
  • 38
  • 146
  • 211

2 Answers2

9

I am writing an application and a feature is that if the user opens youtube.com then not allow him to do this.

Fortunately, malware authors have limited ability to do things like this.

So I planned to kill the Android browser process if the user try to open it.

Fortunately, this is impossible, at least on Android 2.1+.

I know that this code kills the process

Only if you have rights to kill that process. Fortunately, you do not have rights to kill that process.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
3

If it is a webview they are opening the url in then you could use the public boolean shouldOverrideUrlLoading (WebView view, String url) this gives the host application a chance to take over the control when a new url is about to be loaded in the current WebView.

example:

WebViewClient yourWebClient = new WebViewClient()
{
   // Override page
   @Override
   public boolean shouldOverrideUrlLoading(WebView  view, String  url)
   {
        // This line we let me load only pages inside Firstdroid Webpage
        if ( url.contains("youtube") == true )
            //Load new URL & override URL Link
            return true;

        // Return false to not override url loading.
        return false;
   }
};
Kenny
  • 5,522
  • 2
  • 18
  • 29