Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用parse的Android推送在一段时间后停止工作_Android_Parse Platform_Push Notification_Google Cloud Messaging_Google Play Services - Fatal编程技术网

使用parse的Android推送在一段时间后停止工作

使用parse的Android推送在一段时间后停止工作,android,parse-platform,push-notification,google-cloud-messaging,google-play-services,Android,Parse Platform,Push Notification,Google Cloud Messaging,Google Play Services,我使用Parse在Android上发送有针对性的推送通知。遵循教程几次(包括不眠之夜),效果非常好,但是在某些不可预测的事件中,应用程序的android用户会停止接收通知。这当然是在谷歌Play上上传更新几个小时后发生的 为了在不上传到Google Play的情况下复制它,我将它缩小到从清单中更新应用程序的版本号,然后在不删除和重新安装的情况下重新运行。然而,在清单中做一个简单的更改可以使它再次工作。但是,该解决方案不可靠,因为它将在几个小时后/上传到生产后再次停止工作 我使用一个自定义接收器来

我使用Parse在Android上发送有针对性的推送通知。遵循教程几次(包括不眠之夜),效果非常好,但是在某些不可预测的事件中,应用程序的android用户会停止接收通知。这当然是在谷歌Play上上传更新几个小时后发生的

为了在不上传到Google Play的情况下复制它,我将它缩小到从清单中更新应用程序的版本号,然后在不删除和重新安装的情况下重新运行。然而,在清单中做一个简单的更改可以使它再次工作。但是,该解决方案不可靠,因为它将在几个小时后/上传到生产后再次停止工作

我使用一个自定义接收器来播放自定义声音。我正在使用Google Play Services 5进行位置更新。我正在订阅我在以后的活动中推动的频道。你知道是什么导致了这样的问题吗?代码粘贴如下:

显示

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xxx.xxx"
    android:versionCode="19"
    android:versionName="3.077" >

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>
    <!-- GCM PERMISSIONS -->
    <permission android:name="com.xxx.xxx.permission.C2D_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="com.xxx.xxx.permission.C2D_MESSAGE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-permission android:name="com.xxx.xxx.permission.MAPS_RECEIVE" />
    <application
        android:name="com.xxx.xxx.MyApplication"
        android:allowBackup="true"
        android:allowClearUserData="true"
        android:enabled="true"
        android:icon="@drawable/icon"
        android:logo= "@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <uses-library android:name="com.google.android.maps" />

        <service android:name="com.xxx.xxx.xxxLocationService" />

         <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="xxxxxxxxxxx"/>
        <meta-data android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data android:name="com.parse.push.gcm_sender_id"
                    android:value="id:xxxxx" />
        <service android:name="com.parse.PushService" />
        <receiver android:name="com.parse.ParseBroadcastReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.USER_PRESENT" />
            </intent-filter>
        </receiver>
        <receiver android:name="com.xxx.xxx.xxxBroadcastReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="com.parse.push.intent.RECEIVE" />
                <action android:name="com.parse.push.intent.DELETE" />
                <action android:name="com.parse.push.intent.OPEN" />
            </intent-filter>
        </receiver>
        <receiver android:name="com.parse.GcmBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                <!--
                  IMPORTANT: Change "com.parse.starter" to match your app's package name.
                -->
                <category android:name="com.xxx.xxx" />
            </intent-filter>
        </receiver>
    </application>

</manifest>
依赖关系

dependencies {
    compile 'com.google.android.gms:play-services:5.+'
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
    compile 'com.android.support:support-v4:22.0.0'
    compile files('libs/PayPal_MPL.jar')
    compile files('libs/libGoogleAnalyticsServices.jar')
    compile 'com.parse.bolts:bolts-android:1.1.4'
    compile fileTree(dir: 'libs', include: 'Parse-*.jar')
    compile files('libs/Parse-1.8.3.jar')
}
解析广播接收机

public class xxxBroadcastReceiver extends ParsePushBroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        try {
            String jsonData = intent.getExtras().getString("com.parse.Data");
            JSONObject json = new JSONObject(jsonData);

            String title = null;
            if(json.has("title")) {
                title = json.getString("title");
            }

            String message = null;
            if(json.has("alert")) {
                message = json.getString("alert");
            }

            if(message != null) {
                generateNotification(context, title, message);
            }
        } catch(Exception e) {
            Log.e("NOTIF ERROR", e.toString());
        }
    }


    private void generateNotification(Context context, String title, String message) {
        Intent intent = new Intent(context, MainActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0);

        NotificationManager mNotifM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        if(title == null) {
            title = context.getResources().getString(R.string.app_name);
        }

        final NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(context)
                        .setSmallIcon(R.drawable.icon)
                        .setContentTitle(title)
                        .setContentText(message)
                        .setStyle(new NotificationCompat.BigTextStyle()
                                .bigText(message))
                        .addAction(0, "View", contentIntent)
                        .setAutoCancel(true)
                        .setDefaults(new NotificationCompat().DEFAULT_VIBRATE)
                        .setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.whistle));

        mBuilder.setContentIntent(contentIntent);

        mNotifM.notify(randInt(100000000, 999999999), mBuilder.build());
    }

    public static int randInt(int min, int max) {

        // NOTE: Usually this should be a field rather than a method
        // variable so that it is not re-seeded every call.
        Random rand = new Random();

        // nextInt is normally exclusive of the top value,
        // so add 1 to make it inclusive
        int randomNum = rand.nextInt((max - min) + 1) + min;

        return randomNum;
    }

}
订阅频道

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_jobs);

    ...

    ParsePush.subscribeInBackground("driver");
}
更新

下面是我目前如何再现这个问题的。我在调试模式下运行,它可以工作,然后我更改应用程序的版本号,并导出已签名的应用程序用于生产(不运行)。我将已签名的APK安装到设备上(删除后),通知停止工作。似乎覆盖ParsePushBroadcastReceiver与此无关。如果我用相同的版本号删除并在调试模式下重新运行,它将无法工作,直到我更改清单中的某些内容,如BroadcastReceiver。这是我设法复制它的方式,但是当它到达Google Play(现在再试一次)时,通知无论如何都会停止工作。我错过了什么

以下是评论:

// Check if app was updated; if so, it must clear the registration ID
// since the existing registration ID is not guaranteed to work with
// the new app version.

我肯定你会遇到这个。因此,解决方案是在更新后注册你的应用程序。我想在您的情况下,最好的选择是查看
PACKAGE\u REPLACED
事件,在那里您应该再次注册您的应用程序。还请检查它是如何工作的。

您是否尝试过在Parse Dashboard上的应用程序设置中将Released in-Production(生产中发布)开关拨到ON(打开)位置?是的,它已打开。可能是谷歌出于某种原因阻止了GCM的应用程序吗?我没主意了。在版本号更改后,您的
onReceive
也不会被调用?还有,您可以共享哪些日志?在纯GCM实现中(意味着无解析),如果出现问题,响应错误将发送回应用服务器。
// Check if app was updated; if so, it must clear the registration ID
// since the existing registration ID is not guaranteed to work with
// the new app version.