Android 解析不会推送通知,但会显示已注册的用户
解析不会将通知推送到用户。但它显示了站点中的注册用户 这是我的密码: MainActivity.javaAndroid 解析不会推送通知,但会显示已注册的用户,android,parse-platform,Android,Parse Platform,解析不会将通知推送到用户。但它显示了站点中的注册用户 这是我的密码: MainActivity.java public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceSt
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
ParseApplication.java
public class ParseApplication extends Application{
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
Parse.initialize(this, "xxxx", "xxxx");
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
ParseReceiver.java
public class ParseReceiver extends BroadcastReceiver{
private final String TAG = "Parse Notification";
private String msg = "";
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
Log.i(TAG, "PUSH RECEIVED!!!");
try {
String action = arg1.getAction();
String channel = arg1.getExtras().getString("com.parse.Channel");
JSONObject json = new JSONObject(arg1.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(arg0.getResources(),
R.drawable.happy);
Intent launchActivity = new Intent(arg0, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(arg0, 0, launchActivity, 0);
Notification noti = new NotificationCompat.Builder(arg0)
.setContentTitle("PUSH RECEIVED")
.setContentText(msg)
.setSmallIcon(R.drawable.happy)
.setLargeIcon(icon)
.setContentIntent(pi)
.setAutoCancel(true)
.build();
NotificationManager nm = (NotificationManager)arg0.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(0, noti);
}
}
public class Receiver extends ParsePushBroadcastReceiver{
@Override
protected void onPushOpen(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
Intent i = new Intent(arg0,MainActivity.class);
i.putExtras(arg1.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
arg0.startActivity(i);
}
}
Receiver.java
public class ParseReceiver extends BroadcastReceiver{
private final String TAG = "Parse Notification";
private String msg = "";
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
Log.i(TAG, "PUSH RECEIVED!!!");
try {
String action = arg1.getAction();
String channel = arg1.getExtras().getString("com.parse.Channel");
JSONObject json = new JSONObject(arg1.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(arg0.getResources(),
R.drawable.happy);
Intent launchActivity = new Intent(arg0, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(arg0, 0, launchActivity, 0);
Notification noti = new NotificationCompat.Builder(arg0)
.setContentTitle("PUSH RECEIVED")
.setContentText(msg)
.setSmallIcon(R.drawable.happy)
.setLargeIcon(icon)
.setContentIntent(pi)
.setAutoCancel(true)
.build();
NotificationManager nm = (NotificationManager)arg0.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(0, noti);
}
}
public class Receiver extends ParsePushBroadcastReceiver{
@Override
protected void onPushOpen(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
Intent i = new Intent(arg0,MainActivity.class);
i.putExtras(arg1.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
arg0.startActivity(i);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.parse"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="11" />
<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"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
< uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:protectionLevel="signature"
android:name="com.example.parse.permission.C2D_MESSAGE" />
<uses-permission android:name="com.example.parse.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:name="com.example.parse.ParseApplication"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
>
<activity
android:name="com.example.parse.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<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.example.parse.Receiver"
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="com.example.parse"/>
</intent-filter>
</receiver>
<meta-data android:name="com.parse.push.notification_icon"
android:resource="@drawable/ic_launcher"/>
</application>
</manifest>
对不起……我听不懂。。