jpush / jpush-phonegap-plugin

JPush's officially supported PhoneGap/Cordova plugin (Android & iOS). 极光推送官方支持的 PhoneGap/Cordova 插件(Android & iOS)。
https://docs.jiguang.cn
MIT License
925 stars 350 forks source link

android: 调用 getRegistrationID 无法获取值 #415

Open cipchk opened 5 years ago

cipchk commented 5 years ago

WARNING: 如果不按照这个表格,我们将无法帮助你,并将忽略你的问题。

你的运行环境

Installed platforms:
  android 8.0.0
Available platforms: 
  browser ^6.0.0
  electron ^1.0.0
  ios ^5.0.0
  osx ^5.0.0
  windows ^7.0.0

期望效果

获取到 getRegistrationID

实际效果

始终无法获取。

重现步骤

以下是获取 getRegistrationID 的动作:

const _get = () => this.jpush.getRegistrationID().then(_handle);
const _handle = (gid: string) => {
    if (!gid) {
        setTimeout(_get, 1000 * 3);
        return ;
    }
    // Http request
};

_get();

尝试以下几种方式,依然无法获取:

2019-08-27 03:00:16.123 9472-9711/com.xxx.xx D/JIGUANG-JCore: [JCoreHelper] runActionWithService action:init
2019-08-27 03:00:43.841 9472-9472/com.xxx.xx D/JIGUANG-JCore: [JCoreHelper] runActionWithService action:change_foreground
cipchk commented 5 years ago

@Anberm 补充一下我完整的 AndroidManifest.xml 内容:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="2" android:versionName="0.0.2" package="com.xxx.xx" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:networkSecurityConfig="@xml/network_security_config" android:supportsRtl="true" android:usesCleartextTraffic="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <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="v6mo9z" />
            </intent-filter>
        </activity>
        <provider android:authorities="${applicationId}.opener.provider" android:exported="false" android:grantUriPermissions="true" android:name="io.github.pwlin.cordova.plugins.fileopener2.FileProvider">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/opener_paths" />
        </provider>
        <meta-data android:name="com.openinstall.APP_KEY" android:value="v6mo9z" />
        <activity android:exported="false" android:name="cn.jpush.android.ui.PopWinActivity" android:theme="@style/MyDialogStyle" />
        <activity android:configChanges="orientation|keyboardHidden" android:exported="false" android:name="cn.jpush.android.ui.PushActivity" android:theme="@android:style/Theme.NoTitleBar">
            <intent-filter>
                <action android:name="cn.jpush.android.ui.PushActivity" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="com.xxx.xx" />
            </intent-filter>
        </activity>
        <service android:exported="false" android:name="cn.jpush.android.service.PushService" android:process=":pushcore">
            <intent-filter>
                <action android:name="cn.jpush.android.intent.REGISTER" />
                <action android:name="cn.jpush.android.intent.REPORT" />
                <action android:name="cn.jpush.android.intent.PushService" />
                <action android:name="cn.jpush.android.intent.PUSH_TIME" />
            </intent-filter>
        </service>
        <provider android:authorities="com.xxx.xx.DataProvider" android:exported="false" android:name="cn.jpush.android.service.DataProvider" android:process=":pushcore" />
        <service android:enabled="true" android:exported="true" android:name="cn.jpush.android.service.DaemonService">
            <intent-filter>
                <action android:name="cn.jpush.android.intent.DaemonService" />
                <category android:name="com.xxx.xx" />
            </intent-filter>
        </service>
        <provider android:authorities="com.xxx.xx.DownloadProvider" android:exported="true" android:name="cn.jpush.android.service.DownloadProvider" />
        <receiver android:enabled="true" android:exported="false" android:name="cn.jpush.android.service.PushReceiver">
            <intent-filter android:priority="1000">
                <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" />
                <category android:name="com.xxx.xx" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.USER_PRESENT" />
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_ADDED" />
                <action android:name="android.intent.action.PACKAGE_REMOVED" />
                <data android:scheme="package" />
            </intent-filter>
        </receiver>
        <receiver android:exported="false" android:name="cn.jpush.android.service.AlarmReceiver" />
        <receiver android:name="cn.jiguang.cordova.push.JPushEventReceiver">
            <intent-filter>
                <action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />
                <category android:name="com.xxx.xx" />
            </intent-filter>
        </receiver>
        <activity android:exported="true" android:name="cn.jpush.android.service.JNotifyActivity" android:taskAffinity="jpush.custom" android:theme="@android:style/Theme.Translucent.NoTitleBar">
            <intent-filter>
                <action android:name="cn.jpush.android.intent.JNotifyActivity" />
                <category android:name="com.xxx.xx" />
            </intent-filter>
        </activity>
        <service android:name="cn.jiguang.cordova.push.PushService" android:process=":pushcore">
            <intent-filter>
                <action android:name="cn.jiguang.user.service.action" />
            </intent-filter>
        </service>
        <receiver android:enabled="true" android:exported="false" android:name="cn.jiguang.cordova.push.JPushReceiver">
            <intent-filter>
                <action android:name="cn.jpush.android.intent.REGISTRATION" />
                <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" />
                <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" />
                <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" />
                <action android:name="cn.jpush.android.intent.CONNECTION" />
                <category android:name="com.xxx.xx" />
            </intent-filter>
        </receiver>
        <meta-data android:name="JPUSH_CHANNEL" android:value="developer-default" />
        <meta-data android:name="JPUSH_APPKEY" android:value="xxxxxxxxx" />
    </application>
    <permission android:name="com.xxx.xx.permission.JPUSH_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE" />
    <uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
    <uses-sdk android:minSdkVersion="19" />
</manifest>

请问我目前还有哪些因素导致无法获取的,目前小米、华为手机都无法获取。

另还有一些相应 libs 的结构如下:

android/app/libs/jcore-android-2.1.2.jar
android/app/libs/jpush-android-3.3.4.jar
app/src/main/java/cn/jiguang/cordova/push/JPushEventReceiver.java
app/src/main/java/cn/jiguang/cordova/push/JPushPlugin.java
app/src/main/java/cn/jiguang/cordova/push/JPushReceiver.java
app/src/main/java/cn/jiguang/cordova/push/PushService.java
cipchk commented 5 years ago

之前一直未使用 Andoird Studio 打开过 Ionic4 生成的项目,我不确定是哪里引起的,当我尝试使用 Andoird Studio 打开项目后,竟然可以获取到设备ID了。

细节我无法追溯,但这是一个解决思路之一,希望获取不到设备ID的也可以尝试一下。

同时希望官方要是有时间,可以在这个思路上做一些深入的解析,这样可以让更多的人了解根本因素。

另一点,我不确定是不是我使用的是最新版本的 Ionic,目前 jpush-phonegap-plugin 插件对应的配置无法完全跟 AndroidManifest.xml 自动合并,会出现部件插件所需要的权限无法合并,从而导致有些权限缺失。