MR. Kumar
MR. Kumar

Reputation: 679

Is it possible to close browser tab in android programmatically?

I have an app which plays music from a local server and opens music player in the web browser but when the user goes back to the Home activity and launches Another activity which plays a video on the browser, The video opens in a different tab of the browser, while music tab does not get closed.

Can I close an already opened browser tab when another tab opens? If not. Please suggest some workarounds.

Upvotes: 3

Views: 4109

Answers (3)

nixxo_raa
nixxo_raa

Reputation: 402

it isn;t the good way to do so, if you are interested in this then the code would be like this

List<ActivityManager.RunningAppProcessInfo> list = servMng.getRunningAppProcesses();
if(list != null){
 for(int i=0;i<list.size();++i){
  if("com.android.browser".matches(list.get(i).processName)){
   int pid = android.os.Process.getUidForName("com.android.browser");
         android.os.Process.killProcess(pid);
  }
 }
}

Upvotes: 0

MR. Kumar
MR. Kumar

Reputation: 679

After lots of struglling ,i reached on conclusion,we cant handle the operation of other application without permission by owner of application,so i have found alternet solution using webview now its working.

Upvotes: 3

Mr.Me
Mr.Me

Reputation: 9286

You can't control another applications life-cycle . so you can't close tabs that are running in the browser.

what you can do on the other hand is to use WebView to open the audio/video then you have full control over it (what and when) to load/close content.

Upvotes: 4

Related Questions