从Parse.com的推送通知中提取文本

时间:2014-08-11 07:51:09

标签: android text push-notification parse-platform message

我收到Parse.com提供的推送通知时无法获取文字

我的onCreate()

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    tv = (TextView) findViewById(R.id.textView1);

    Parse.initialize(this, "HDTss5xhd88H0uTmNBhCx4wWxfxVht6Cm5hWhbt8", "Y3KGXmndgySCla8yhrzgvT2d5uIJhg0WDI8MJyPB");

    PushService.setDefaultPushCallback(getApplicationContext(), MainActivity.class);

    WebView myWebView = (WebView) findViewById(R.id.webView1);
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    myWebView.setWebViewClient(new WebViewClient());
    myWebView.loadUrl("file:///android_asset/Qiyas/index.html");
}

我的Manifest.xml

<receiver android:name="pushReceiver" >
        <intent-filter>
            <action android:name="MyAction" >
            </action>
        </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.example.myfirstpush" />
        </intent-filter>
    </receiver>

我的pushReceiver.class

public class pushReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    Bundle extras = intent.getExtras();
    String message = extras != null ? extras.getString("com.parse.Data")
            : "";
    JSONObject jObject;
    try {
        jObject = new JSONObject(message);
        Toast toast = Toast.makeText(context, jObject.getString("alert")
                + jObject.getString("title") + jObject.getString("action"),
                Toast.LENGTH_LONG);
        toast.show();
        Log.d("Riceieved",
                jObject.getString("alert") + jObject.getString("title")
                        + jObject.getString("action"));
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

我收到推送通知,但我想提取其中的文字 谢谢,

1 个答案:

答案 0 :(得分:0)

您需要纠正 AndroidManifest.xml -

<service android:name="com.parse.PushService" />
<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>
<receiver android:exported="false" android:name="PushReceiver_Class">
    <intent-filter>
        <!-- Choose According to need. -->
        <action android:name="Your_Package_Name.UPDATE_STATUS" />
        <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>

您可以找到更多信息 Here.