非保护广播会导致应用启动时崩溃

时间:2017-03-21 23:05:38

标签: android broadcastreceiver android-service android-notifications android-broadcastreceiver

每次在后端更新数据时,我都会收到接收通知的服务。这是服务的代码:

public class FeedbackService extends IntentService {

public FeedbackService() {
    super("FeedbackService");
}

@Override
protected void onHandleIntent(Intent intent) {
    Log.d("MyService", "About to execute feedback call");

    feedbackCheckCall(this);
}

private void feedbackCheckCall(final Context context){
  //Call for getting checking data from backend.

}

private void sendNotification(Context context) {
    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_launcher_icon)
                    .setContentTitle("Feedback Reply")
                    .setContentText("You've a reply waiting for your feedback!")
                    .setVibrate(new long[]{500,500,500});

    Intent notificationIntent = new Intent(context, navHomeActivity.class );
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(contentIntent);

    // Add as notification
    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(0, builder.build());
}

}

这是接收者的代码:

public class FeedbackRecieiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    Intent dailyUpdater = new Intent(context, FeedbackService.class);

    context.startService(dailyUpdater);

    Log.d("AlarmReceiver", "Called context.startService from AlarmReceiver.onReceive");
}
}

以下是我称之为的代码:

    Calendar updateTime = Calendar.getInstance();
    updateTime.setTimeZone(TimeZone.getDefault());
    updateTime.set(Calendar.HOUR_OF_DAY,0);
    updateTime.set(Calendar.MINUTE, 0);
    updateTime.set(Calendar.SECOND, 0);

    long intervalTime = 2*60*60*1000; //in milliseconds format is : h*m*s*1000

    Intent intent = new Intent(context, FeedbackRecieiver.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent pendingIntent = PendingIntent.getBroadcast(context,0,intent,PendingIntent.FLAG_CANCEL_CURRENT);

    AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);

    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,updateTime.getTimeInMillis(),intervalTime,pendingIntent);

我的清单声明是:

 <service android:name=".navFragments.feedbackSuppport.FeedbackService"/>
 <receiver  android:name=".navFragments.feedbackSuppport.FeedbackRecieiver"/>

当我在启动时使用带有此错误的签名副本时,应用程序崩溃了:

 Sending non-protected broadcast com.motorola.motocare.INTENT_TRIGGER from system 6836:com.motorola.process.system/1000 pkg com.motorola.motgeofencesvc
                                               java.lang.Throwable
                                                   at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:18179)
                                                   at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:18779)
                                                   at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:512)
                                                   at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2905)
                                                   at android.os.Binder.execTransact(Binder.java:565)

有人可以帮我解决这个问题吗?我真的被困在这里了。提前谢谢。

1 个答案:

答案 0 :(得分:0)

因此,广播接收器或服务没有问题。问题是在使用proguard时。我没有正确使用它。我在调试版本中禁用了它,并在发布版本中启用了它。该应用程序因此而崩溃。