通知未显示

时间:2016-07-14 09:35:05

标签: android broadcastreceiver android-notifications

我创建了一个broadcast receiver来接收来自Google Fused Location API的位置更新。在我的广播接收器中,我已设置通知以显示位置坐标。最初,一切都运转良好,但是,现在我无法收到通知。

这是我的logcat:

07-14 14:55:01.730 1129-1129/? I/dalvikvm: DexOpt: access denied from Landroid/support/v4/app/NotificationCompatKitKat; to field Landroid/app/Notification;.actions
07-14 14:55:05.274 510-525/? D/IPCThreadState: [DN #5] BR_CLEAR_DEATH_NOTIFICATION_DONE cookie 0x56f982f8
07-14 14:55:05.411 510-745/? D/IPCThreadState: [DN #5] BR_CLEAR_DEATH_NOTIFICATION_DONE cookie 0x597bfe08
07-14 14:55:05.580 804-815/? D/IPCThreadState: [DN #5] BR_CLEAR_DEATH_NOTIFICATION_DONE cookie 0x576cca28
07-14 14:55:07.493 26570-28863/? D/IPCThreadState: [DN #5] BR_CLEAR_DEATH_NOTIFICATION_DONE cookie 0x51612400
07-14 14:55:07.499 26570-28864/? D/IPCThreadState: [DN #5] BR_CLEAR_DEATH_NOTIFICATION_DONE cookie 0x516297e8
07-14 14:55:07.510 26570-28863/? D/IPCThreadState: [DN #5] BR_CLEAR_DEATH_NOTIFICATION_DONE cookie 0x5160d788
07-14 14:55:07.518 26570-26582/? D/IPCThreadState: [DN #5] BR_CLEAR_DEATH_NOTIFICATION_DONE cookie 0x51681818
07-14 14:55:07.538 26570-26581/? D/IPCThreadState: [DN #5] BR_CLEAR_DEATH_NOTIFICATION_DONE cookie 0x5165bd50
07-14 14:55:07.554 26570-28864/? D/IPCThreadState: [DN #5] BR_CLEAR_DEATH_NOTIFICATION_DONE cookie 0x51617630
07-14 14:55:07.557 510-521/? D/IPCThreadState: [DN #5] BR_CLEAR_DEATH_NOTIFICATION_DONE cookie 0x597bfe08
07-14 14:55:07.648 1179-1179/com.svtech.thirdeye.thirdeye I/dalvikvm: Could not find method android.app.Notification$Builder.setLocalOnly, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
07-14 14:55:07.648 1179-1179/com.svtech.thirdeye.thirdeye W/dalvikvm: VFY: unable to resolve virtual method 242: Landroid/app/Notification$Builder;.setLocalOnly (Z)Landroid/app/Notification$Builder;
07-14 14:55:07.648 1179-1179/com.svtech.thirdeye.thirdeye I/dalvikvm: DexOpt: access denied from Lcom/google/android/gms/common/GooglePlayServicesUtil; to field Landroid/app/Notification;.extras
07-14 14:55:07.722 1179-1179/com.svtech.thirdeye.thirdeye I/dalvikvm: Could not find method android.app.Notification$Builder.setLocalOnly, referenced from method gsi.a
07-14 14:55:07.722 1179-1179/com.svtech.thirdeye.thirdeye W/dalvikvm: VFY: unable to resolve virtual method 527: Landroid/app/Notification$Builder;.setLocalOnly (Z)Landroid/app/Notification$Builder;
07-14 14:55:07.722 1179-1179/com.svtech.thirdeye.thirdeye I/dalvikvm: DexOpt: access denied from Lgsi; to field Landroid/app/Notification;.extras
07-14 14:55:07.950 1179-1179/com.svtech.thirdeye.thirdeye I/dalvikvm: Could not find method android.app.Notification$Builder.setLocalOnly, referenced from method kk.a
07-14 14:55:07.951 1179-1179/com.svtech.thirdeye.thirdeye W/dalvikvm: VFY: unable to resolve virtual method 1338: Landroid/app/Notification$Builder;.setLocalOnly (Z)Landroid/app/Notification$Builder;
07-14 14:55:07.951 1179-1179/com.svtech.thirdeye.thirdeye I/dalvikvm: DexOpt: access denied from Lkk; to field Landroid/app/Notification;.extras

这是我的BroadCast Receiver课程:

public class LocationHandlerReceiver extends BroadcastReceiver {

    public static final int NOTIFICATION_ID = 1;

    public LocationHandlerReceiver() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {

        if (LocationResult.hasResult(intent)) {
            LocationResult locationResult = LocationResult.extractResult(intent);
            Location mLocation = locationResult.getLastLocation();
            Log.i("Intent Service", mLocation.toString());

            setupNotification(context, mLocation);
        }
    }


    //Setup Notification
    private void setupNotification(Context context, Location location) {

        PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
                new Intent(context, MainActivity.class), 0);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.location_start_notification)
                .setContentTitle(context.getResources().getString(R.string.location_notification))
                .setContentText("Lat: " + location.getLatitude() + ", Long: " + location.getLongitude());
        mBuilder.setContentIntent(contentIntent);
        mBuilder.setAutoCancel(true);
        mBuilder.setLocalOnly(false);
        mBuilder.setOngoing(true);
        NotificationManager mNotificationManager =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

    }
}

PS:我在Android 4.2.2,API 17上测试应用。在我的前几次运行中,显示了通知。

编辑:这是我的Manifest文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.svtech.thirdeye.thirdeye">

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />

 <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        android:name="android.support.multidex.MultiDexApplication">

        ..........

      <receiver
            android:name=".BroadcastReceivers.LocationHandlerReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="thirdeye.LOCATION_RECEIVED" />

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </receiver>
    </application>

任何人都可以帮我识别问题????

1 个答案:

答案 0 :(得分:1)

首先将此权限添加到您的清单文件中:

input

然后删除<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 行,并按照以下方式进行操作:

<category android:name="android.intent.category.LAUNCHER"/>