How to Pause/Destroy webview showing youtube video when PowerOff button is pressed?

This thread was migrated from an old forum. It may contain information that are no longer valid. For further assistance, please post a new question or open a support ticket from the Customer Support portal.

Dear community, my app has not being approved by Android because the app enables background playing of YouTube videos (YouTube video continues to play after pressing power button and the screen is off) - how can I pause the video if the power button is pressed or simply how can I know if the power button is pressed?

Regards

@Joe Axwvhvm​ Looks like something you can help on?

Hi,

Code snippets reference :

http://chandan-tech.blogspot.in/2010/10/handling-screen-lock-unlock-in-android.html

Step1:

Currently you have to extend the auto generated activity (created under src/<packagename>/Applicationname.java )and add the

private BroadcastReceiver mReceiver;//Add this deceleration in onCreate of extended activity.

//add the below lines of code in to your onCreate() method,

//soon after calling super method.[i.e super.onCreate()]

IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);

filter.addAction(Intent.ACTION_SCREEN_OFF);

filter.addAction(Intent.ACTION_USER_PRESENT);

// Customized BroadcastReceiver class

//Will be defined soon..

mReceiver = new ScreenReceiver();

registerReceiver(mReceiver, filter);

Step 2:Rest of the broadcast receiver code can go in as FFI.

Step 3: Register a invoke JS callback with FFI and invoke it once you receive the power event.

In JS callback you can pause the video.

Step 4:

You have to change the Main launcher Activity usign "Tags tab: "->"Child Tag Entries under Main Launcher <activity> tag:" as indicated under link below to the overridden Activity which registers and unregister broadcast receivers.

http://docs.kony.com/konylibrary/visualizer/visualizer_user_guide/Content/Native_App_Properties.htm

Attached contents of blog as Doc for future reference in case blog link goes down

Additionally please raise it as feature request to incorporate the power events support in platform itself.

Thanks and Regards

Hi, thank you for your help.

It's the first time I need to do FFI - do you have any recommendation article or example to share?

Right now I have added the code for step1

Step2 I need to find how to create FFI

Step3 Same

Step4 I found the place but what do I have to write?

Regards

Hi,

Please have a look at these.

http://docs.kony.com/6_5/konylibrary/studio/studio_user_guide/Content/Foreign_Function_Interface_JS.htm

https://community.kony.com/developer/forum/how-make-use-ffi-android-library-project

Please let us know if you need any more info.

Regards