Android解析sdk推送通知

标签 android push-notification parse-platform

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/

相关文章:

c# - 即将到来的 GCM 响应是 : Error=NotRegistered

ios - 使用 React Native 前端和 Java Spring 后端创建推送通知系统?

ios - 重新加载应用程序后如何禁止用户喜欢帖子?

javascript - 使用 Node.js 和 Mailgun 发送 HTML 时遇到问题

android - 非法参数异常 : Service not registered:

android - 作业调度服务

Android InApp 购买错误代码 102

java - Activity Intent 子级不向父级返回数据,不显示 toast

javascript - 如果浏览器关闭/Web 推送,FCM 推送通知会排队

javascript - 在 Express 中使用 Parse.Cloud.httpRequest 时出现问题,表示没有这样的成功方法 :