如何将我的安卓应用程序注册到解析网站

3
我该如何在Parse推送网站上注册我的安卓应用程序或设备,以便接收通知?目前我已连接到GCM,但无法进一步注册我的设备到Parse...

请参考以下链接:https://parse.com/tutorials/android-push-notifications。 - sasikumar
http://www.sitepoint.com/creating-cloud-backend-android-app-using-parse/ - sasikumar
请参考以下网址:http://www.androidhive.info/2015/06/android-push-notifications-using-parse-com/。 - sasikumar
3个回答

2

以下是我根据个人经验多次尝试和实践以及阅读众多SO和Parse帖子总结出来的最佳方式,在标准推送通知中实现正式的Parse SDK。接下来,我将逐步引导您完成以下步骤:

  1. Add the following dependencies to the app build.gradle file, and you can get the latest versions from Parse github blank projects or Parse SDK from docs category in the website. the latest versions until now is here:

    compile 'com.parse.bolts:bolts-tasks:1.3.0'
    compile 'com.parse:parse-android:1.11.0'
    
  2. Add the following codes similar to the quick guide in the Application class's onCreate() method of the project, change the keys accordingly --> Take attention that these two lines must be added after super.onCreate(); :

    // Enable Local Datastore.
    Parse.enableLocalDatastore(this);
    
    // Add your initialization code here
    Parse.initialize(this, "YOUR APPLICATION ID", "YOUR CLIENT KEY");
    ParseInstallation.getCurrentInstallation().saveInBackground();
    
    ParseUser.enableAutomaticUser();
    ParseACL defaultACL = new ParseACL();
    // Optionally enable public read access.
    // defaultACL.setPublicReadAccess(true);
    ParseACL.setDefaultACL(defaultACL, true);
    
  3. Add the following line after setContentView in your MainActivity class:

    ParseAnalytics.trackAppOpenedInBackground(getIntent());
    
  4. add the Parse service and receivers to AndroidManifest.xml immediately before the closing </application> tag and make the mentioned package names identical to the yours:

    <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" />
    
        <!--
          IMPORTANT: Change "com.parse.starter" to match your app's package name.
        -->
        <category android:name="com.parse.starter" />
      </intent-filter>
    </receiver>
    
  5. add permissions like the quick guide instructions typically immediately before the opening <application> tag, and make the mentioned package names identical to the yours, too:

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    
    <!--
      IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
      to match your app's package name + ".permission.C2D_MESSAGE".
    -->
    <permission android:protectionLevel="signature"
        android:name="com.parse.starter.permission.C2D_MESSAGE" />
    <uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />
    

最后一步) 完成!享受推送您的内容吧。 ;)


1
将以下代码添加到您的清单中。
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

 <permission
    android:name="${your_application_package}.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="${your_application_package}.permission.C2D_MESSAGE" />

<application
    android:name="${your_application_package}.ParseApplication"
    android:allowBackup="true"
    android:icon="@drawable/contact_image"
    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>
    <!-- Parse library -->
    <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.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" />

            <!-- IMPORTANT: Change "com.parse.starter" to match your app's package name. -->
            <category android:name="${your_application_package}" />
        </intent-filter>
    </receiver>

您的ParseApplication应该像这样:
public class ParseApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        //TODO: replace application_id and ClientKey with your parse credentials
        Parse.initialize(this, "application_id", "ClientKey");
        ParseInstallation.getCurrentInstallation().saveInBackground();
    }
}

将 bolts-android-1.2.0 和 Parse-1.9.2 库添加到您的项目中。现在运行应用程序并在解析仪表板中检查,您会发现您的设备已注册。

非常感谢大家...现在我能够从Parse推送通知到我的应用程序了。 - mtrivedi

0

我刚从Parse网站下载了一个推送应用程序的示例...在下载的解决方案中将有2个项目...1个是iOS,另一个是Android...iOS不能直接推送...所以我们需要将Android项目设置为启动项目并运行我们的应用程序...这样您的手机就会被您的Parse网站检测到,并转到仪表板中的推送选项卡,选择发送推送...在文本框中写入您想要推送的信息,然后单击“立即发送”...这样推送信息将出现在您的移动设备上。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接