How to use @capacitor/core - 10 common examples

To help you get started, we’ve selected a few @capacitor/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github abritopach / angular-ionic-ngxs-movies / src / app / pages / detail / detail.ts View on Github external
.subscribe(result => {
      if (result.items.length > 0) {
        console.log(result);
        const { videoId } = result.items[0].id;
        this.movie.videoId = videoId;

        // Code to use capacitor-youtube-player plugin.
        console.log('DetailsPage::watchTrailer -> platform: ' + Capacitor.platform);
        if (Capacitor.platform === 'web') {
          const componentProps = { modalProps: { item: this.movie}};
          this.presentModal(componentProps, YoutubeModalComponent);
        } else { // Native
          this.testYoutubePlayerPlugin();
        }

        /*
        if (Capacitor.platform === 'web') {
          window.open('https://www.youtube.com/watch?v=' + videoId);
        } else { // TODO: Use capacitor-youtube-player plugin.
          window.open('https://www.youtube.com/watch?v=' + videoId, '_blank');
        }
        */
      }
    },
    error => {
github abritopach / ionic-offline-mode / src / app / services / network.service.ts View on Github external
constructor(private toastController: ToastController, private loadingCtrl: LoadingController) {
    console.log('NetworkService::constructor | method called');

    let status = ConnectionStatus.Offline;
    if (Capacitor.platform === 'web') {
      console.log('WEB');
      console.log('navigator.onLine', navigator.onLine);
      this.addConnectivityListenersBrowser();
      status =  navigator.onLine === true ? ConnectionStatus.Online : ConnectionStatus.Offline;
    } else { // Native: use capacitor network plugin
      console.log('NATIVE');
      this.addConnectivityListernerNative();
      // status = Network.getStatus();
    }

    this.status.next(status);
  }
github abritopach / angular-ionic-ngxs-movies / src / app / pages / detail / detail.ts View on Github external
.subscribe(result => {
      if (result.items.length > 0) {
        console.log(result);
        const { videoId } = result.items[0].id;
        this.movie.videoId = videoId;

        // Code to use capacitor-youtube-player plugin.
        console.log('DetailsPage::watchTrailer -> platform: ' + Capacitor.platform);
        if (Capacitor.platform === 'web') {
          const componentProps = { modalProps: { item: this.movie}};
          this.presentModal(componentProps, YoutubeModalComponent);
        } else { // Native
          this.testYoutubePlayerPlugin();
        }

        /*
        if (Capacitor.platform === 'web') {
          window.open('https://www.youtube.com/watch?v=' + videoId);
        } else { // TODO: Use capacitor-youtube-player plugin.
          window.open('https://www.youtube.com/watch?v=' + videoId, '_blank');
        }
        */
      }
    },
github aaronksaunders / capacitor-vue-ionicv4-app / src / components / CameraPage.vue View on Github external
async takePicture() {
      let isAvailable = true;

      if (!isAvailable) {
        // Have the user upload a file instead
        alert("No Camera Aailable");
      } else {
        // Otherwise, make the call:

        try {
          const image = await Camera.getPhoto({
            quality: 90,
            allowEditing: true,
            resultType: CameraResultType.DataUrl,
            source: CameraSource.Prompt
          });
          console.log("image", image);
          // image.base64_data will contain the base64 encoded result as a JPEG, with the data-uri prefix added
          this.imageUrl = image.dataUrl;
          // can be set to the src of an image now

          console.log(image);
        } catch (e) {
          console.log("error", e);
        }
      }
    }
  }
github ionic-team / capacitor / example / src / pages / camera / camera.ts View on Github external
async testAndroidBreak() {
    const image = await Plugins.Camera.getPhoto({
      allowEditing: false,
      correctOrientation: true, // <------------ oups
      height: 1080,
      width: 1080,
      quality: 90,
      resultType: CameraResultType.DataUrl,
      saveToGallery: false, 
      source: CameraSource.Photos
    });
    console.log('Got image back', image.path, image.webPath, image.format, image.exif);
    this.image = this.sanitizer.bypassSecurityTrustResourceUrl(image && (image.dataUrl));
  }
}
github ModusCreateOrg / beep / src / main.js View on Github external
async function initCapacitor() {
  // Platform checks
  Vue.prototype.$isWeb = helpers.isWeb()
  Vue.prototype.$isIOS = helpers.isIOS()

  // Set status-bar background and style
  StatusBar.setBackgroundColor({ color: helpers.env('INITIAL_STATUSBAR_COLOR') }).catch(helpers.err)
  StatusBar.setStyle({ style: StatusBarStyle.Light }).catch(helpers.err)

  // Set network checks
  Network.getStatus()
    .then(s => (Vue.prototype.$networkStatus = s))
    .catch(helpers.err)

  // Listen to network changes
  Network.addListener('networkStatusChange', s => (Vue.prototype.$networkStatus = s)).catch(
    helpers.err
  )
}
github ionic-team / capacitor / example / src / pages / local-notifications / local-notifications.ts View on Github external
async scheduleNowWithIcon() {
    this.notifs = await Plugins.LocalNotifications.schedule({
      notifications: [{
        title: 'Get 10% off!',
        body: 'Swipe now to learn more',
        // Android-only: set a custom statusbar icon 
        smallIcon: "res://ic_stat_icon_sample",
        // Get random id to test cancel
        id: Math.floor(Math.random()*10),
        sound: 'beep.aiff',
        attachments: [
          { id: 'face', url: 'res://public/assets/ionitron.png' }
        ],
        actionTypeId: 'OPEN_PRODUCT',
        extra: {
          productId: 'PRODUCT-1'
        }
      }]
github ionic-team / capacitor / example / src / pages / browser / browser.ts View on Github external
constructor(public navCtrl: NavController, public navParams: NavParams) {
    Plugins.Browser.addListener('browserFinished', (info: any) => {
      console.log('Browser all done!');
    });
    Plugins.Browser.addListener('browserPageLoaded', (info: any) => {
      console.log('Browser page loaded!');
    });
    Plugins.Browser.prefetch({
      urls: ["https://ionicframework.com/"]
    });
  }
github ionic-team / capacitor / plugin-template / src / web.ts View on Github external
platforms: ['web']
    });
  }

  async echo(options: { value: string }): Promise<{value: string}> {
    console.log('ECHO', options);
    return options;
  }
}

const MyPlugin = new MyPluginWeb();

export { MyPlugin };

import { registerWebPlugin } from '@capacitor/core';
registerWebPlugin(MyPlugin);
github jgw96 / Wavex / src / components / track-detail / track-detail.tsx View on Github external
async share() {
    console.log(location.href);
    console.log(location.origin);
    console.log(location.hostname);

    let shareURL = location.href;

    if (location.origin.includes('localhost')) {
      shareURL = `https://wavex-app.firebaseapp.com/${location.pathname}`;
    }

    if (Haptics) {
      Haptics.impact({
        style: HapticsImpactStyle.Light
      })
    }

    if (Share && !(window as any).Windows) {
      await Share.share({
        title: 'wavex',
        text: 'Check out this podcast!',
        url: shareURL,
        dialogTitle: 'Share this podcast'
      });
    }
    else if ((window as any).Windows) {
      console.log('trying to share');
      const DataTransferManager = (window as any).Windows.ApplicationModel.DataTransfer.DataTransferManager;

      const dataTransferManager = DataTransferManager.getForCurrentView();