gpt4 book ai didi

android - BroadcastReceiver 试图在无序广播期间返回结果 Weird Error

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:28:18 25 4
gpt4 key购买 nike

即使我没有发送推送通知,首次启动应用程序时也会出现此错误:

 BroadcastReceiver trying to return result during a non-ordered broadcast
java.lang.RuntimeException: BroadcastReceiver trying to return result during a non-ordered broadcast
at android.content.BroadcastReceiver.checkSynchronousHint(BroadcastReceiver.java:799)
at android.content.BroadcastReceiver.setResultCode(BroadcastReceiver.java:565)
at com.pushnotification.GcmBroadcastReceiver.onReceive(GcmBroadcastReceiver.java:17)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2712)
at android.app.ActivityThread.access$1700(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5696)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

BroadcastReceiver 的代码:

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Explicitly specify that GcmIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(),
GcmIntentService.class.getName());

// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));

/* the crash is pointing to this line */
setResultCode(Activity.RESULT_OK);
}
}

在我在 IntentService 中实现以下代码后,错误开始出现(也没有在应用程序启动时调用)。但也不是每次,I.E.从 Android Studio 卸载并运行应用程序后,有时会发生错误,有时不会。

BroadcastReceiver receiver;
public void DownloadListener(final String ZipFile) {
receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();

if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);

DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(downloadReference);
Cursor c = downloadManager.query(query);

if (c.moveToFirst()) {
int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
DismissProgressDialog();
ShowProgress("Almost Done", "Unzipping And Installing Database", pd.STYLE_SPINNER);
}
}
}
}
};

context.registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}

在 list 中:

<receiver
android:name="com.pushnotification.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.geovision.ffmsnativeprototype" />
</intent-filter>
</receiver>

<service android:name=".WebServiceCommunication.SystemDatabaseService" />

按照 another question 的答案建议注释掉 setResultCode(Activity.RESULT_OK); 行后推送通知的 IntentService 收到了包含此内容的通知

From-google.com/iid-Title-null-Message-null-ExtraData-null

我的情况与Weird push message received on app start相同

最佳答案

根据答案https://stackoverflow.com/a/30508934/1950784

这是一个与 google 相关的功能,不是什么大问题,可以通过编程方式进行过滤。

@Override
protected void onHandleIntent(Intent intent) //RECEIVE THE PUSHNOTIFICATION
{

Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
// The getMessageType() intent parameter must be the intent you received
// in your BroadcastReceiver.
String messageType = gcm.getMessageType(intent);

if (!extras.isEmpty()) { // has effect of unparcelling Bundle
/*
* Filter messages based on message type. Since it is likely that GCM
* will be extended in the future with new message types, just ignore
* any message types you're not interested in, or that you don't
* recognize.
*/
if (GoogleCloudMessaging.
MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
// sendNotification("Send error: " + extras.toString());
} else if (GoogleCloudMessaging.
MESSAGE_TYPE_DELETED.equals(messageType)) {
// sendNotification("Deleted messages on server: " +
// extras.toString());
// If it's a regular GCM message, do some work.
} else if (GoogleCloudMessaging.
MESSAGE_TYPE_MESSAGE.equals(messageType)) {


Log.i(TAG, "PUSHNOTIFICATION RECEIVED @ " + SystemClock.elapsedRealtime());


extraData=extras.getString("extraData");
from=extras.getString("from");
title=extras.getString("title");
message=extras.getString("message");

Log.i(TAG, "Received: " + extras.toString()+" M"+messageType);




if(title!=null) {
                    if(from.equals("google.com/iid"))
{
//related to google ... DO NOT PERFORM ANY ACTION
}
else {
//HANDLE THE RECEIVED NOTIFICATION
}

关于android - BroadcastReceiver 试图在无序广播期间返回结果 Weird Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30568625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com