asc*_*sco 9 android android-notifications google-cloud-messaging
我有一个GcmListenerService侦听GCM消息,然后创建一个通知:
public class MyGcmListenerService extends GcmListenerService {
NotificationManager notificationManager;
@Override
public void onMessageReceived(final String from, final Bundle data) {
super.onMessageReceived(from, data);
notificationManager = (NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
String title = data.getString("title");
String messager = data.getString("message");
Notification notification = new NotificationCompat.Builder(getApplicationContext())
// set title, message, style etc
.build();
notificationManager.notify(0, notification);
}
}
Run Code Online (Sandbox Code Playgroud)
一切都很标准.这对于成千上万的用户而言每天工作数千次.我确实通过Crashlytics收到了上述几行的以下崩溃:
致命异常:java.lang.RuntimeException无法在未调用Looper.prepare()的线程内创建处理程序
这种情况几乎完全发生在Android 6(98%)和制造商称为TCLCommunications的设备上.
任何人都已经经历过这样的事情,或者知道这是关于什么的?
从后台线程创建通知应该是完全可以的,对吧?
| 归档时间: |
|
| 查看次数: |
250 次 |
| 最近记录: |