微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我需要 Android localNotifications 的特定权限吗?

如何解决我需要 Android localNotifications 的特定权限吗?

我们最近向公众发布了适用于 iOS 和 Android 的新应用,但只有 iOS 会显示任何通知。我们正在使用 localnotifications 和 SweetAlert2 向用户显示他们已收到进入新公园的护照徽章,如果应用程序未打开,则让用户知道收到徽章,并提示用户在他们收到后 15 分钟进行调查离开公园。

注意:当通过 debug.apk 文件在我的 Android 设备上测试时,localnotifications 工作得很好,但在启动到生产后,这些功能停止工作。

有人告诉我,我们可能需要在 Android 上获得特定权限,但这是权限问题吗?如果是这样,我需要哪些?是在AndroidManifest.xml中添加权限那么简单吗?

这是我的代码

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="yes.usa.stateparks"
  xmlns:tools="http://schemas.android.com/tools">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
            android:name="yes.usa.stateparks.MainActivity"
            android:label="@string/title_activity_main"
            android:theme="@style/AppTheme.NoActionBarLaunch"
            android:launchMode="singleTask">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.broWSABLE" />
                <data android:scheme="@string/custom_url_scheme" />
            </intent-filter>

        </activity>

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
          <Meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths" />
        </provider>
    </application>

    <!-- Permissions -->

    <uses-permission android:name="android.permission.INTERNET" />
    <!-- Camera,Photos,input file -->
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <!-- Geolocation API -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-feature android:name="android.hardware.location.gps" />
    <!-- Network API -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <!-- Navigator.getUserMedia -->
    <!-- Video -->
    <uses-permission android:name="android.permission.CAMERA" tools:node="remove" />
    <!-- Audio -->
    <uses-permission android:name="android.permission.RECORD_AUdio" tools:node="remove" />
    <uses-permission android:name="android.permission.MODIFY_AUdio_SETTINGS"/>
</manifest>

通知代码


  async badgeNotification(park: Park) {
    await this.localnotifications.schedule({
      title: 'New Passport Badge!',text: `You just earned a new passport badge for visiting ${park.title}!`,id: 1,foreground: true,data: park
    });

    await Swal.fire({
      title: 'Badge Unlocked!',text: 'You\'ve unlocked a new badge! Check it out on your passport.',confirmButtonText: 'Sweet,thanks!',imageUrl: `/assets/img/badges/color/${park.url_title}.png`,imageWidth: 150,buttonsstyling: false,customClass: {
        title: 'font-slab'
      }
    }).then((result) => {
      if (result.isConfirmed) {
        const navExtras: NavigationExtras = {
          state: {
            passport: true
          }
        };
        this.router.navigate(['/profile'],navExtras);
      }
    });
  }

  async surveyNotification(park: string) {
    await this.localnotifications.schedule({
      title: 'Thanks for Visiting!',text: `Thank you for visiting ${park}. If you have time,`
      + `we would love it if you Could fill out a brief survey telling us how we did.`,id: 2,trigger: { at: new Date(new Date().getTime() + 1000 * 60 * 15 ) },});

    this.storage.set('survey_on_next_open',true);
  }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。