【问题标题】:Parse.com Android Push Notifications With UrlParse.com 带有 URL 的 Android 推送通知
【发布时间】:2014-10-16 11:58:53
【问题描述】:

我正在尝试通过推送通知将解析集成到我的应用程序中,并让通知显示自定义文本并在我向其发送 url 时打开设备的浏览器。

解析集成很好(这是简单的部分),但我卡住的地方是要为集成编写什么代码来处理解析接口发送的 json 代码,并让应用程序将其转换为我需要完成的操作。

我知道我必须更新清单文件和主要活动类才能完成此操作,但我被卡住了。

【问题讨论】:

    标签: android json parse-platform push


    【解决方案1】:

    将清单添加到

    <receiver android:name="com.sample.app.android.recevier.PushNotificationRecevier" >
       <intent-filter>
         <action android:name="com.sample.app.android.SIMPLE_NOTIFICATION" />
       </intent-filter>
    </receiver>
    

    创建一个接收器类

    import org.json.JSONException;
    import org.json.JSONObject;
    
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    
    public class PushNotificationRecevier extends BroadcastReceiver{
        String SimpleNotification="com.sample.app.android.SIMPLE_NOTIFICATION";
        @Override
        public void onReceive(Context context, Intent intent) {
            if(intent.getAction().equalsIgnoreCase(SimpleNotification)){
    
                // Your Stuff 
    JSONObject jsonObject=new JSONObject(intent.getExtras().getString("com.parse.Data"));
    
    
            }
        }
    }
    

    【讨论】:

    • 好的,但不知道在“你的东西”区域放什么。我知道它必须解码 json 查询(我将对如何构建它进行玩具研究,因为我对 java 和 json 还是新手)。但也会出现以下错误:Broadcast Receiver, Context and Intent cannot be resolve to a type.
    • 你可以使用 JSONObject jsonObject=new JSONObject(intent.getExtras().getString("com.parse.Data"));表单获取json对象然后你可以解析你自己的方式。
    • 好的,最终通过 eclipse 的大量检查得到了验证。 Nw 用于 JSON 代码。我希望能够发送文本和 url 以便在浏览器中打开推送。在您的代码中,我只看到 appID、packageName 和 versionCode。我可以通过这些,但我应该通过什么来发送自定义标题、文本和 url。像这样:{ “title”: “You Have a New Message”, “alert”: “这里有一些文字”, “url”: “someurl.com” }
    • 如果有用请查看我的回答
    • 好的,感谢您的更新 :) 好的 所以看起来它现在会接受并解析出 JSON 数据,但是需要构建什么构造函数来实际构建通知,以便正确发送所有内容?在你的资料下,我将其编辑为: String title=jsonObject.getString("title");字符串警报=jsonObject.optString("警报");字符串 url=jsonObject.optString("url");
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多