简体   繁体   English

使用parse.com Android无法推送通知?

[英]Push notification is not working using parse.com android?

I have created simple push notification app using parse.com. 我使用parse.com创建了简单的推送通知应用程序。

devices registered successfully on parse.com but when i try to send push notification through parse.com no notification have come. 设备已在parse.com上成功注册,但是当我尝试通过parse.com发送推送通知时,没有通知。

AndroidMainifest.xml Code: AndroidMainifest.xml代码:

    <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.GET_ACCOUNTS" />
    <permission android:protectionLevel="signature"
        android:name="com.parse.starter.permission.C2D_MESSAGE" />
    <uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />
service android:name="com.parse.PushService" />
        <receiver android:name="com.parse.ParsePushBroadcastReceiver"
            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.parse.starter" />
            </intent-filter>
        </receiver>

        <meta-data
            android:name="com.parse.APPLICATION_ID"
            android:value="" />
        <meta-data
            android:name="com.parse.CLIENT_KEY"
            android:value="" />

Reciever Code: 收件人代码:

    public class Receiver extends ParsePushBroadcastReceiver {

    private Intent parseIntent;

    public Receiver() {
        super();
    }

    @Override
    protected void onPushReceive(Context context, Intent intent) {
        super.onPushReceive(context, intent);

        if (intent == null)
            return;

        try {
            JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));

            parseIntent = intent;

        } catch (JSONException e) {
            Log.d("PushJsonException", "" + e.getMessage());
        }
    }
}

MainActivity Code: MainActivity代码:

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Parse.initialize(this);
        ParseInstallation.getCurrentInstallation().saveInBackground();
    }

    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // Call Methods to Update Your Stuff
        }
    };
    @Override
    protected void onResume() {
        super.onResume();
        LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, new IntentFilter("com.example.harrypotter.pushnotificationdemo"));
    }

    @Override
    protected void onPause() {
        super.onPause();
        LocalBroadcastManager.getInstance(this).unregisterReceiver(mBroadcastReceiver);

    }

Application Class : 申请类别:

public class ParseApp extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Parse.initialize(this);
        ParseInstallation.getCurrentInstallation().saveInBackground();
    }
}

Parse.com Hosted Service is fully retiring on January 28, 2017. If you have an existing application, refer to this link and create your own push notification server. Parse.com托管服务将于2017年1月28日完全停用。如果您已有应用程序,请参考此链接并创建自己的推送通知服务器。 Parse release a database migration tool that lets you migrate data from your Parse app to any MongoDB database. Parse发布了一个数据库迁移工具,可让您将数据从Parse应用程序迁移到任何MongoDB数据库。

For More Information Check The LInk 有关更多信息,请检查直线

You have not changed the Category attribute in your Manifest file: 您尚未在清单文件中更改类别属性:

 <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.GET_ACCOUNTS" />
<permission android:protectionLevel="signature"
    android:name="com.parse.starter.permission.C2D_MESSAGE" />
<uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />
service android:name="com.parse.PushService" />
    <receiver android:name="com.parse.ParsePushBroadcastReceiver"
        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>

IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below to match your app's package name + ".permission.C2D_MESSAGE". 重要信息:在下面的行中更改“ com.parse.starter.permission.C2D_MESSAGE”,以匹配您应用的程序包名称+“。permission.C2D_MESSAGE”。

    <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="YOUR PACKAGE NAME" />
        </intent-filter>
    </receiver>

    <meta-data
        android:name="com.parse.APPLICATION_ID"
        android:value="" />
    <meta-data
        android:name="com.parse.CLIENT_KEY"
        android:value="" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM