如何使用Parse.com推送通知服务在Android应用中推送网址?

时间:2015-05-18 14:23:54

标签: java android json parse-platform push-notification

我可以推送简单的推送通知,但无法推送网址在浏览器中打开它。

我看到他们建议创建自定义JSON接收器类的在线教程很少。谁能告诉我怎么做?

MainActivity.java

 package com.example.pushnotificationdemo;



import com.example.pushnotificationdemo.R;
import com.parse.ParseAnalytics;
import com.parse.ParseInstallation;
import com.parse.PushService;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends ActionBarActivity {

    WebView webframe;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);



        setContentView(R.layout.activity_main);

        ParseAnalytics.trackAppOpenedInBackground(getIntent());

        PushService.setDefaultPushCallback(this, MainActivity.class);
        ParseInstallation.getCurrentInstallation().saveInBackground();



        /** Cerco l'elemento in /res/layout/main.xml */
        webframe = (WebView) findViewById(R.id.webview);

        /** Javascript abilitato (ma non flash) */
        webframe.getSettings().setJavaScriptEnabled(true);



        /** Simulo il webbrowser chrome di android*/
        webframe.setWebChromeClient(new WebChromeClient()); 
        webframe.setWebViewClient(new WebViewClient()); 

        /** Assegno l'url di apertura del webframe */
        webframe.loadUrl("http://www.daiugs.com");






    }
}

ParseApp.java

package com.example.pushnotificationdemo;

import com.parse.Parse;
import com.parse.ParseACL;
import com.parse.ParseUser;

import android.app.Application;

public class ParseApp extends Application{

    @Override
    public void onCreate() {
        super.onCreate();

        Parse.initialize(this, "Ym4IsX0r5dGLxa8RDtj....",
                "s9DpBvn8HI0Uu......");

        ParseUser.enableAutomaticUser();
        ParseACL defaultACL = new ParseACL();

        defaultACL.setPublicReadAccess(true);

        ParseACL.setDefaultACL(defaultACL, true);
    }

}

的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.pushnotificationdemo"
    android:versionCode="1"
    android:versionName="1.0" >

    <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.SYSTEM_ALERT_WINDOW"/>


    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:name=".ParseApp" >

       <activity android:name="com.example.pushnotificationdemo.SplashActivity"
                  android:label="@string/app_name"
                 android:screenOrientation="portrait">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>




        </activity>

       <activity android:name="com.example.pushnotificationdemo.MainActivity"
                  android:label="@string/app_name"

                  >




            </activity>

        <service android:name="com.parse.PushService"></service>

                <receiver android:name="com.example.pushnotificationdemo.MyCustomReceiver" android:exported="false">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />
            <action android:name="your.package.name.UPDATE_STATUS" />
        </intent-filter>
    </receiver>



        <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>

    </application>

</manifest>

1 个答案:

答案 0 :(得分:0)

在推送时发送

data: {
    alert: "Android Push Gets Major Refresh",
    url: "http://blog.parse.com",
  }

并在mainActivity中添加它

Intent intent = getIntent();
Bundle extras = intent.getExtras();
String jsonData = extras.getString("com.parse.Data");
JSONObject json = new JSONObject(jsonData);
String pushStore = json.getString("url");
if(pushStore!=null) {
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(pushStore));
  startActivity(browserIntent);
}