解析 Android 上的接收通知
Parse receiving notifications on Android
在我的 android 应用程序中,当我尝试在 logcat 中接收推送通知时出现此错误:
6-22 14:38:16.016 6570-6570/com.tekinarslan.material.sample
E/com.parse.ManifestInfo﹕ Cannot use GCM for push because the app
manifest is missing some required declarations. Please make sure that
these permissions are declared as children of the root
element:
Also, please make sure that these services and broadcast receivers are declared as children of the element:
06-22 14:38:16.021 6570-6570/com.tekinarslan.material.sample E/com.parse.PushService﹕
Tried to use push, but this app is not configured for push due to:
Push is not configured for this app because the app manifest is
missing required declarations. Please add the following declarations
to your app manifest to support either GCM or PPNS for push (or both).
To enable GCM support, please make sure that these permissions are
declared as children of the root element:
Also, please make sure that these services and broadcast receivers are declared as children of the element:
To enable PPNS support, please make sure that these permissions are declared as children of the root element:
Also, please make sure that these services and broadcast receivers are declared as children of the element:
我想我的清单里有我需要的一切,这里是:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tekinarslan.material.sample"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="9"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- Permissions required for parse.com notifications -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<!-- END Parse permissions -->
<!--
IMPORTANT: Change "com.parse.tutorials.pushnotifications.permission.C2D_MESSAGE" in the lines below
to match your app's package name + ".permission.C2D_MESSAGE".
-->
<permission android:protectionLevel="signature"
android:name="com.tekinarslan.material.sample.permission.C2D_MESSAGE" />
<uses-permission android:name="com.tekinarslan.material.sample.permission.C2D_MESSAGE" />
<application
android:name=".App"
android:allowBackup="true"
android:label="DONUT"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>
<activity
android:name=".SampleActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name=".FbLoginActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
<!-- My custom receiver -->
<receiver android:name=".ParseReceiver" >
<intent-filter>
<action android:name="com.tekinarslan.material.sample.RECEIVE_PUSH" />
</intent-filter>
</receiver>
<!-- END my custom receiver -->
<!-- Required for Parse.com notifications -->
<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>
<!-- END Parse.com requirements -->
</application>
</manifest>
**我的 ParseReceiver - **
package com.tekinarslan.material.sample;
import java.util.Iterator;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
/*****************************
* This class will receive custom push notifications
* from parse.com. These are different than the "plain"
* message push notifications.
*
* There must be an action defined within the Intent-Filter
* for this receiver in the manifest.xml file. And the same
* action must be specified on the notification when it is
* pushed.
*
* You can optionally pass JSON data from parse.com which will
* be avaialable in the onReceive() method here.
*****************************/
public class ParseReceiver extends BroadcastReceiver {
private final String TAG = "Parse Notification";
private String msg = "";
@Override
public void onReceive(Context ctx, Intent intent) {
Log.i(TAG, "PUSH RECEIVED!!!");
try {
String action = intent.getAction();
String channel = intent.getExtras().getString("com.parse.Channel");
JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
Log.d(TAG, "got action " + action + " on channel " + channel + " with:");
Iterator itr = json.keys();
while (itr.hasNext()) {
String key = (String) itr.next();
Log.d(TAG, "..." + key + " => " + json.getString(key));
if(key.equals("string")){
msg = json.getString(key);
}
}
} catch (JSONException e) {
Log.d(TAG, "JSONException: " + e.getMessage());
}
Bitmap icon = BitmapFactory.decodeResource(ctx.getResources(),
R.drawable.ic_launcher);
Intent launchActivity = new Intent(ctx, SampleActivity.class);
PendingIntent pi = PendingIntent.getActivity(ctx, 0, launchActivity, 0);
Notification noti = new NotificationCompat.Builder(ctx)
.setContentTitle("PUSH RECEIVED")
.setContentText(msg)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(icon)
.setContentIntent(pi)
.setAutoCancel(true)
.build();
NotificationManager nm = (NotificationManager)ctx.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(0, noti);
}
}
您的自定义接收器需要在 intent-filters 中执行以下操作:
<receiver
android:name=".ParseReceiver"
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"/>
<category android:name="at.a1telekom.android.newsroom"/>
</intent-filter>
</receiver>
编辑:
你订阅这样的解析吗?
Parse.initialize(context, appId, clientKey);
ParsePush.subscribeInBackground( yourChannels, new SaveCallback() {...});
您缺少清单中的给定代码。在 Manifest 文件底部的标记前包含给定代码。
<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.tutorials.pushnotifications" to match your app's package name. -->
<category android:name="com.tekinarslan.material.sample" />
</intent-filter>
</receiver>
<receiver
android:name="com.tekinarslan.material.sample.NotificationReceiver"
android:exported="false" >
<intent-filter>
<action android:name="com.tekinarslan.material.sample.UPDATE_STATUS" />
</intent-filter>
</receiver>
在我的 android 应用程序中,当我尝试在 logcat 中接收推送通知时出现此错误:
6-22 14:38:16.016 6570-6570/com.tekinarslan.material.sample E/com.parse.ManifestInfo﹕ Cannot use GCM for push because the app manifest is missing some required declarations. Please make sure that these permissions are declared as children of the root element: Also, please make sure that these services and broadcast receivers are declared as children of the element: 06-22 14:38:16.021 6570-6570/com.tekinarslan.material.sample E/com.parse.PushService﹕ Tried to use push, but this app is not configured for push due to: Push is not configured for this app because the app manifest is missing required declarations. Please add the following declarations to your app manifest to support either GCM or PPNS for push (or both). To enable GCM support, please make sure that these permissions are declared as children of the root element: Also, please make sure that these services and broadcast receivers are declared as children of the element: To enable PPNS support, please make sure that these permissions are declared as children of the root element: Also, please make sure that these services and broadcast receivers are declared as children of the element:
我想我的清单里有我需要的一切,这里是:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tekinarslan.material.sample"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="9"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- Permissions required for parse.com notifications -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<!-- END Parse permissions -->
<!--
IMPORTANT: Change "com.parse.tutorials.pushnotifications.permission.C2D_MESSAGE" in the lines below
to match your app's package name + ".permission.C2D_MESSAGE".
-->
<permission android:protectionLevel="signature"
android:name="com.tekinarslan.material.sample.permission.C2D_MESSAGE" />
<uses-permission android:name="com.tekinarslan.material.sample.permission.C2D_MESSAGE" />
<application
android:name=".App"
android:allowBackup="true"
android:label="DONUT"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>
<activity
android:name=".SampleActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name=".FbLoginActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
<!-- My custom receiver -->
<receiver android:name=".ParseReceiver" >
<intent-filter>
<action android:name="com.tekinarslan.material.sample.RECEIVE_PUSH" />
</intent-filter>
</receiver>
<!-- END my custom receiver -->
<!-- Required for Parse.com notifications -->
<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>
<!-- END Parse.com requirements -->
</application>
</manifest>
**我的 ParseReceiver - **
package com.tekinarslan.material.sample;
import java.util.Iterator;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
/*****************************
* This class will receive custom push notifications
* from parse.com. These are different than the "plain"
* message push notifications.
*
* There must be an action defined within the Intent-Filter
* for this receiver in the manifest.xml file. And the same
* action must be specified on the notification when it is
* pushed.
*
* You can optionally pass JSON data from parse.com which will
* be avaialable in the onReceive() method here.
*****************************/
public class ParseReceiver extends BroadcastReceiver {
private final String TAG = "Parse Notification";
private String msg = "";
@Override
public void onReceive(Context ctx, Intent intent) {
Log.i(TAG, "PUSH RECEIVED!!!");
try {
String action = intent.getAction();
String channel = intent.getExtras().getString("com.parse.Channel");
JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
Log.d(TAG, "got action " + action + " on channel " + channel + " with:");
Iterator itr = json.keys();
while (itr.hasNext()) {
String key = (String) itr.next();
Log.d(TAG, "..." + key + " => " + json.getString(key));
if(key.equals("string")){
msg = json.getString(key);
}
}
} catch (JSONException e) {
Log.d(TAG, "JSONException: " + e.getMessage());
}
Bitmap icon = BitmapFactory.decodeResource(ctx.getResources(),
R.drawable.ic_launcher);
Intent launchActivity = new Intent(ctx, SampleActivity.class);
PendingIntent pi = PendingIntent.getActivity(ctx, 0, launchActivity, 0);
Notification noti = new NotificationCompat.Builder(ctx)
.setContentTitle("PUSH RECEIVED")
.setContentText(msg)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(icon)
.setContentIntent(pi)
.setAutoCancel(true)
.build();
NotificationManager nm = (NotificationManager)ctx.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(0, noti);
}
}
您的自定义接收器需要在 intent-filters 中执行以下操作:
<receiver
android:name=".ParseReceiver"
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"/>
<category android:name="at.a1telekom.android.newsroom"/>
</intent-filter>
</receiver>
编辑:
你订阅这样的解析吗?
Parse.initialize(context, appId, clientKey);
ParsePush.subscribeInBackground( yourChannels, new SaveCallback() {...});
您缺少清单中的给定代码。在 Manifest 文件底部的标记前包含给定代码。
<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.tutorials.pushnotifications" to match your app's package name. -->
<category android:name="com.tekinarslan.material.sample" />
</intent-filter>
</receiver>
<receiver
android:name="com.tekinarslan.material.sample.NotificationReceiver"
android:exported="false" >
<intent-filter>
<action android:name="com.tekinarslan.material.sample.UPDATE_STATUS" />
</intent-filter>
</receiver>