解析Android推送通知收不到
Posted
技术标签:
【中文标题】解析Android推送通知收不到【英文标题】:Parse Android Push notification fails to be received 【发布时间】:2015-07-22 18:37:36 【问题描述】:我一直在尝试使用 Parse 获取通知,根据它发送通知的页面,但模拟器一无所获。请帮忙:(
我的班级
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.parse.Parse;
import com.parse.ParseInstallation;
import com.parse.PushService;
public class FARQ_UANL extends ActionBarActivity
private int cont=0;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_farq__uanl);
//Parse
Parse.initialize(this, "key", "key");
PushService.setDefaultPushCallback(this, FARQ_UANL.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
final WebView myWebView = (WebView) this.findViewById(R.id.pagweb);
myWebView.loadUrl("http://www.arquitectura.uanl.mx/");
Button btn1 = (Button) findViewById(R.id.home);
Button btn2 = (Button) findViewById(R.id.calendario);
Button btn3 = (Button) findViewById(R.id.buzon);
Button btn4 = (Button) findViewById(R.id.mapa);
Button btn5 = (Button) findViewById(R.id.directorio);
Button btn6 = (Button) findViewById(R.id.faq);
btn1.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
myWebView.loadUrl("http://www.arquitectura.uanl.mx/");
cont++;
if(cont==6)
//toast
Toast tostito =
Toast.makeText(getApplicationContext(),
"Bienvenido al infierno", Toast.LENGTH_SHORT);
tostito.show();
);
btn2.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
myWebView.loadUrl("http://www.arquitectura.uanl.mx/calendario.html");
cont=0;
);
btn3.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
myWebView.loadUrl("http://arquitectura.uanl.mx/buzondesugerencias.html");
cont=0;
);
btn4.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
myWebView.loadUrl("http://arquitectura.uanl.mx/instalaciones.html");
cont=0;
);
btn5.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
myWebView.loadUrl("http://arquitectura.uanl.mx/directorio.html");
cont=0;
);
btn6.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
myWebView.loadUrl("http://arquitectura.uanl.mx/informacion.html#faq");
cont=0;
);
安卓清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="karudia.com.farq" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<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" />
<!--
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="karudia.com.farq.permission.C2D_MESSAGE" />
<uses-permission android:name="karudia.com.farq.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/iniciales"
android:theme="@style/AppTheme" >
<activity
android:name=".FARQ_UANL"
android:label="@string/iniciales" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<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="karudia.com.farq" />
</intent-filter>
</receiver>
</application>
如果有人知道使用推送通知的另一种方式,请告诉我
【问题讨论】:
【参考方案1】:这部分你把你的Application类的onCreate方法放在了
//Parse
Parse.initialize(this, "key", "key");
PushService.setDefaultPushCallback(this, FARQ_UANL.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
【讨论】:
以上是关于解析Android推送通知收不到的主要内容,如果未能解决你的问题,请参考以下文章