Android parse sdk 推送通知在模拟器上运行,但是当我使用 usb 调试在手机上运行它时,推送通知在后端触发,可以在我的 parse.com 帐户中看到,但手机没有没有收到推送通知。
public class Profile_InviteActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile__invite);
Bundle extras = getIntent().getExtras();
ParseQuery<ParseObject> query = ParseQuery.getQuery("UserProfile");
Log.d("id",""+extras.getInt("fid"));
query.whereEqualTo("fid", ""+extras.getInt("fid"));
query.findInBackground(new FindCallback<ParseObject>() {
public void done(final List<ParseObject> scoreList, ParseException e) {
if (e == null) {
TextView name = (TextView) findViewById(R.id.profile_name);
TextView location = (TextView) findViewById(R.id.profile_location);
name.setText(scoreList.get(0).getString("name"));
location.setText(scoreList.get(0).getString("location"));
ParseFile img1 = (ParseFile)scoreList.get(0).get("profileimage");
img1.getDataInBackground(new GetDataCallback() {
public void done(byte[] data,
ParseException e) {
if (e == null) {
Log.d("test",
"We've got data in data.");
// Decode the Byte[] into
// Bitmap
ImageView image = (ImageView) findViewById(R.id.profimg);
image.setImageBitmap(BitmapFactory
.decodeByteArray(
data, 0,
data.length));
} else {
Log.d("test",
"There was a problem downloading the data.");
}
}
});
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
}
public void inviteToTrain(View v)
{
Log.d("inviting","now");
Bundle extras = getIntent().getExtras();
//ParseInstallation installation = ParseInstallation.getCurrentInstallation();
//installation.put("fids",true);
//installation.saveInBackground();
ParseQuery pushQuery = ParseInstallation.getQuery();
//pushQuery.whereEqualTo("fid", extras.getInt("fid"));
pushQuery.whereEqualTo("fids", true);
// Send push notification to query
ParsePush push = new ParsePush();
push.setQuery(pushQuery); // Set our Installation query
push.setMessage("Someone would like to join you at your event ");
push.sendInBackground();
Log.d("invited","now");
}
请帮我解决这个问题。
谢谢
最佳答案
为了获得推送通知,
您必须编写广播接收器来处理它。
示例代码: 初始化解析细节后,添加这个
PushService.setDefaultPushCallback(this, SampleClass.class);
然后在你的 list 文件中,添加这个
<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>
然后转到解析仪表板,并手动发送推送以检查推送是否进入您的手机。像这样使用Json格式,
{ "alert": "Notification", "title": "Push", "objectId": "objectId",
"objectType": "type", "action": "Your Action Name" }
更多详情,引用
How to trigger an event using Parse for Android via push notification?
关于Android解析sdk推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20606269/