2014-10-16 110 views
1

我試圖解析融入我的應用程序推送通知,並有通知顯示自定義文本,打開設備的瀏覽器,當我髮網址給它。Parse.com Android的推送通知包含URL

解析集成是好的(這就是簡單的一部分),但是我被卡住的地方是爲處理由解析接口發送的json代碼進行集成的代碼,並讓應用程序將其轉化爲我需要完成的操作。

我知道我將不得不更新清單文件和主要活動類來做到這一點,但我堅持。

回答

2

添加艙單

<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")); 


     } 
    } 
} 
+0

好得到了,但不知道要放什麼東西在「你的東西」的區域。我知道它必須解碼json查詢(我將對玩具研究如何構建,因爲我對java和json仍然陌生)。但是也會出現以下錯誤:Broadcast Receiver,Context和Intent無法解析爲類型。 – JRod 2014-10-16 12:26:10

+0

檢查我的最新 – SelvaMariappan 2014-10-16 12:28:32

+0

u可以使用的JSONObject的JSONObject =新的JSONObject(intent.getExtras()的getString( 「com.parse.Data」)); 表單得到json對象然後你可以解析你自己的方式。 – SelvaMariappan 2014-10-16 12:29:24