我构建了一个由网络视图组成的Android应用程序,在parse.com我已经注册了我的设备,但是当我发送推送通知时,推送发送"有0推。 这是我的主动:
import com.party.bparty.MainActivity;
import com.parse.Parse;
import com.parse.ParseInstallation;
import com.parse.ParsePush;
import com.parse.ParseQuery;
import com.parse.PushService;
public class MainActivity extends ActionBarActivity {
private WebView mWebView;
private String url = "http://www.bestparty.altervista.org";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//attivo parse per le notifiche
Parse.initialize(this,"zJxpd9798Ns6A9rzUDpe78ElRY0I99ES3LD6nDQV","kmAmA1iTbC32BTE9ERtzNOoHXbJchhIn6tyPXKMi");
PushService.setDefaultPushCallback(this, MainActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
//...
//...initializing and loading the contentview and the webview
}
//options menu omitted
}
这是我的MycustomReceiver
public class MyCustomReceiver extends BroadcastReceiver {
private static final String TAG = "MyCustomReceiver";
@Override
public void onReceive(Context context, Intent intent) {
try {
if (intent == null)
Log.d(TAG, "Receiver intent null");
else {
String action = intent.getAction();
Log.d(TAG, "got action " + action );
if (action.equals("com.party.bparty.UPDATE_STATUS")) {
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();
if (key.equals("customdata")) {
Intent pupInt = new Intent(context, ShowPopUp.class);
pupInt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
context.getApplicationContext().startActivity(pupInt);
}
Log.d(TAG, "..." + key + " => " + json.getString(key));
}
}
}
}
catch (JSONException e) {
Log.d(TAG, "JSONException: " + e.getMessage());
}
}
}
这是我的ShowPopup
public class ShowPopUp extends Activity implements OnClickListener {
Button ok, cancel;
boolean click = true;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("Cupon");
setContentView(R.layout.popupdialog);
ok = (Button)findViewById(R.id.popOkB);
ok.setOnClickListener(this);
cancel = (Button)findViewById(R.id.popCancelB);
cancel.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
finish();
}
}
这是我的明白
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.party.bparty"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<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.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission
android:name="com.androidhive.pushnotifications.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.androidhive.pushnotifications.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".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>
<activity
android:name="com.party.bparty.ShowPopUp"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
</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.RECEIVE_BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.party.bparty.MyCustomReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="com.iakremera.pushnotificationdemo.UPDATE_STATUS" />
</intent-filter>
</receiver>
</application>
</manifest>
我的错误在哪里?
我这样做,但无论如何它都不起作用 &#34; if(action.equals(&#34; com.party.bparty.UPDATE_STATUS&#34;)){ 选择一个,com.party.bparty.UPDATE_STATUS或com.iakremera.pushnotificationdemo.UPDATE_STATUS&#34; 但现在我有1&#34; PUSH SENT&#34;在发送推送,但我的设备没有显示任何推送
答案 0 :(得分:0)
您的接收器有错误的过滤器。您的接收器声明为:
<receiver android:name="com.party.bparty.MyCustomReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="com.iakremera.pushnotificationdemo.UPDATE_STATUS" />
</intent-filter>
</receiver>
但您正在检查代码中的其他意图操作:
if (action.equals("com.party.bparty.UPDATE_STATUS")) {
选择com.party.bparty.UPDATE_STATUS
或com.iakremera.pushnotificationdemo.UPDATE_STATUS
,并确保Parse在您执行推送时知道它是哪一个。