我试图在我的应用中使用推送通知。我从服务推送通知的站点复制并粘贴了示例代码。当我发送推送时,推送只会来到我的手机和模拟器,而不是所有手机上安装的应用程序。 如果代码有问题,为什么我的手机接到推送?如果没有,为什么其他手机无法接收? (我可以正确地看到我的面板中有多少用户安装了该应用。)
你的想法有什么不对?
你可以在下面看到我的代码。
接收者类:
public class myReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
long reqId= intent.getLongExtra("RequestId", -1);
String msg = intent.getStringExtra("Message");
Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
}}
myApplicaton类:
public class myApplicaton extends SlsApplication implements IFinishedInit {
@Override
public void onCreate() {
super.onCreate();
String sid = "f4439879-8bc1-4c01-87ce-8e98d0f76ccc";
SLS.init(this,sid,this);
}
@Override
public void finishedInit(int i) {
switch (i){
case SLS.RESULT_OK:
Log.i("baas", "RESULT_OK");
break;
case SLS.RESULT_FAILED:
Log.i("baas", "RESULT_FAILED");
break;}
}
}
清单:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.example.pushnotif.permission.C2D_MESSAGE" />
<permission android:name="com.example.pushnotif.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<application
android:name=".myApplicaton"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="ir.sls.android.slspush.Receiver.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.pushnotif" />
</intent-filter>
</receiver>
<service android:name="ir.sls.android.slspush.GcmIntentService" />
<receiver android:name="ir.sls.android.slspush.NetWatcher">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
<receiver android:name=".myReceiver" >
<intent-filter>
<category android:name="com.example.pushnotif" />
<action android:name="ir.sls.android.slspush.ActionSlsPushReceived" />
</intent-filter>
</receiver>
</application>
答案 0 :(得分:1)
请检查是否所有未接收的手机都会生成GCM注册信息..