【发布时间】:2014-02-28 15:17:30
【问题描述】:
我创建了一个使用推送通知的 android 应用程序,但每次我从后端发送通知时,我的 android 平板电脑上都会弹出一个对话框,说“不幸的是 lic 已停止”。我尝试对应用程序进行故障排除,但似乎可以找到错误的来源。
我在 Manifest 中添加了以下权限:
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="com.example.myappname.pemermission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.myappname.permission.C2D_MESSAGE" />
我还注册了一个接收器来处理消息:
<receiver
android:name="com.example.myappname.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.myappname"/>
</intent-filter>
</receiver>
最后,我声明了一个新的meta-data 标签:
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
<activity android:name="noti_handler"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden" />
我的Broadcastreceiver 代码如下:
public class GcmBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent arg) {
String sh = gcm.getMessageType(arg);
Bundle bb= arg.getExtras();
if(!bb.isEmpty()){
if(GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(sh)){
String b=arg.getExtras().getString("message")+"<br>";
String f="handler";
try {
FileOutputStream fos=openFileOutput(f, con.MODE_APPEND);
fos.write(b.getBytes());
fos.close();
} catch (FileNotFoundException ef) {
error(ef.toString());
ef.printStackTrace();
} catch (IOException e) {
error(e.toString());
e.printStackTrace();
}
catch(Exception ex){
error(ex.toString());
}
sendNoti("you have a message/s");//this sends notification to user
try{
}
catch(Exception e){
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
}
}
}
}
}
【问题讨论】:
-
发布 logcat 好友.....
-
我正在使用设备而不是模拟器工作,我似乎无法在我的三星 Galaxy Tab3 上调试应用程序 - 无法从三星网站获取 oem 驱动程序
标签: java android push-notification broadcastreceiver google-cloud-messaging