Draw Over All Apps Cordova Plugin For Android

Android Cordova Plugin that uses draw over all apps feature to display a HTML Web view , it supports displaying HTML file with style files and Javascript libraries and scripts - for now it can not use cordova capabilities -

Install

cordova plugin add cordova-plugin-drawoverapps

It is also possible to install via repo url directly

cordova plugin add https://github.com/ahmedwahba/cordova-plugin-drawoverapps

Functions

  • window.overApps.checkPermission
  • window.overApps.startOverApp
  • window.overApps.closeOverApp

window.overApps.checkPermission

This to check draw-over-apps permession and open system permission window to be granted

  window.overApps.checkPermission(function(msg){
         console.log(msg);
  });

window.overApps.startOverApp

start service function display the over-all head or the web view according to options. If successful the success is called,
otherwise the failed is called instead.

window.overApps.startOverApp(options, success, failed);

Options

  • path: file path to display as view content, this file should be located in WWW root folder.
  • hasHead: display over app head image which open the view up on click , by default true.
  • dragToSide: enable auto move of head to screen side after dragging stop , by default true.
  • enableBackBtn: enable hardware back button to close view , by default true.
  • enableCloseBtn: whether to show native close btn or to hide it , by default true
  • verticalPosition: set vertical alignment of view , values are top - center - bottom , by default center.
  • horizontalPosition: set horizontal alignment of view , values are right - center - left , by default center.

Example

var options = {
      path: "test.html",          // file path to display as view content.
      hasHead: true,              // display over app head image which open the view up on click.
      dragToSide: false,          // enable auto move of head to screen side after dragging stop. 
      enableBackBtn: false,       // enable hardware back button to close view.
      enableCloseBtn: true,      //  whether to show native close btn or to hide it.
      verticalPosition: "top",    // set vertical alignment of view.
      horizontalPosition: "left"  // set horizontal alignment of view. 
 };
 
 window.overApps.startOverApp(options,function (success){
   		console.log(success);
 },function (err){
   		console.log(err);
 });

window.overApps.closeOverApp

It closes over app web view , called inside app itself only .

window.overApps.closeOverApp();

Control overApp WebView

Close WebView

It closes over app webview from one of the webview UI or event

OverApps.closeWebView();
2 Likes

Please can you show an example for how to use it in ionic 2 ?
i mean where exact i can add this plugin functions ? inside [ app.components ? ] or where and can you share this test.html file content example ?

thanks for this plugin

regards

also, after tried to use it inside [ app.components ] i get error when build

OverAppsService.java:82: error: cannot find symbol
         overAppsHead = inflater.inflate(R.layout.service_over_apps_head, null, false);
symbol:   variable layout
  location: class R

also why you import your default or test app like that :

import com.ionicframework.overapp809848.R;

maybe this make the error ?

This is a quick solution you can use this link


to add the plugin to your ionic 2 project as this plugin not an ionic native one
i hope it works with you

for that error if you changed your app id after the plugin installed , just remove the platform then reinstall it again

I know how to use non native plugin in ionic and about [ app id ] i didn’t changed it also however i removed platform and added it again also i changed the app id inside the plugin and added platform again nothing changed and still get this error, so app id not changed automatically !

can you show me example for how and where i can add your code ?
so what i did is :
1- i changed the app id like that :

import com.ionicframework.MY_APP_HERE.R;

2- added platform again
3- i used your plugin like that in [ app.components ] like that :

declare var window;
declare let OverApps: any;
declare let overApps: any;

@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  @ViewChild(Nav) nav: Nav;

  rootPage: any = HomePage;

  pages: Array<{title: string, component: any}>;

  constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen) {
    this.initializeApp();

    // used for an example of ngFor and navigation
    this.pages = [
      { title: 'Home', component: HomePage },
      { title: 'List', component: ListPage }
    ];

  }

  initializeApp() {
    this.platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      this.statusBar.styleDefault();
      this.splashScreen.hide();

        OverApps.checkPermission(function(msg){
           console.log(msg);
        });

       // i tried this code also
       // window.overApps.checkPermission(function(msg){
        //    console.log(msg);
        // });

        var options = {
          path: "test.html",    // file path to display as view content.
          hasHead: true,        // display over app head image which open the view up on click.
          dragToSide: false,    // enable auto move of head to screen side after dragging stop.
          enableBackBtn: false, // enable hardware back button to close view.
          enableCloseBtn: true,  //  whether to show native close btn or to hide it.
          verticalPosition: "bottom",    // set vertical alignment of view.
          horizontalPosition: "right"  // set horizontal alignment of view.
         };

         OverApps.startOverApp(options,function (success){
           		console.log(success);
         },function (err){
           		console.log(err);
         });
         // i tried this code also
         //  window.overApps.startOverApp(options,function (success){
        //    		console.log(success);
        //  },function (err){
        //    		console.log(err);
        //  });

    });
  }

  openPage(page) {
    // Reset the content nav to have just this page
    // we wouldn't want the back button to show in this scenario
    this.nav.setRoot(page.component);
  }
}

4- i added [ test.html ] file inside [ www ] folder which contain this code, just for test :

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
  <meta charset="UTF-8">
  <title>Ionic App</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <meta name="format-detection" content="telephone=no">
  <meta name="msapplication-tap-highlight" content="no">

</head>
<body>

  <img src="assets/icon/favicon.ico" />

</body>
</html>

finally when i build the app by this code :

ionic run android --device

i get this error

BUILD FAILED

Total time: 3.455 secs

Error: 
FULL_URL_TO_PROJECT/platforms/android/src/org/apache/cordova/overApps/Services/OverAppsService.java:81: error: cannot find symbol
         overAppsHead = inflater.inflate(R.layout.service_over_apps_head, null, false);
                                          ^
  symbol:   variable layout
  location: class R
FULL_URL_TO_PROJECT/platforms/android/src/org/apache/cordova/overApps/Services/OverAppsService.java:82: error: cannot find symbol
         overAppsView = inflater.inflate(R.layout.service_over_apps_view, null, false);
                                          ^
  symbol:   variable layout
  location: class R
FULL_URL_TO_PROJECT/platforms/android/src/org/apache/cordova/overApps/Services/OverAppsService.java:83: error: cannot find symbol
         webView = (WebView) overAppsView.findViewById(R.id.webView);
                                                           ^
  symbol:   variable webView
  location: class id
FULL_URL_TO_PROJECT/platforms/android/src/org/apache/cordova/overApps/Services/OverAppsService.java:84: error: cannot find symbol
         imageHead = (ImageView) overAppsHead.findViewById(R.id.imageHead);
                                                               ^
  symbol:   variable imageHead
  location: class id
FULL_URL_TO_PROJECT/platforms/android/src/org/apache/cordova/overApps/Services/OverAppsService.java:85: error: cannot find symbol
         imgClose = (ImageView) overAppsView.findViewById(R.id.imgClose);
symbol:   variable imgClose
  location: class id
FULL_URL_TO_PROJECT/platforms/android/src/org/apache/cordova/overApps/Services/OverAppsService.java:211: error: cannot find symbol
             keyDispatureView = inflater.inflate(R.layout.key_dispature, null, false);
                                                  ^
  symbol:   variable layout
  location: class R
FULL_URL_TO_PROJECT/platforms/android/src/org/apache/cordova/overApps/Services/OverAppsService.java:213: error: cannot find symbol
         rlKeyDispature = (KeyDispatchLayout) keyDispatureView.findViewById(R.id.tab_left);
                                                                                ^
  symbol:   variable tab_left
  location: class id

FAILURE: Build failed with an exception.

system information:

Cordova CLI: 6.5.0 
Ionic Framework Version: 3.4.2
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.3.8
ios-deploy version: 1.9.1 
ios-sim version: 5.0.13 
OS: macOS Sierra
Node Version: v8.0.0
Xcode version: Xcode 8.3.3 Build version 8E3004b

please can you show me complete example for how make this work ?

thanks for advance

please make sure you have the device plugin in your project , don’t put the import line manually
add screen shoot with the exception here

Am getting same issue. Can you resolved means can you please explain how ?

What worked for me, was to open project in Android Studio and got also error message. Then in Android Studio edited appeared line " import undefined.R" in OverAppsService.java which wasn’t there before. Just replaced with package id and then it worked for me -> no package R doesnt exist error any more