Vaibhav Agarwal
Vaibhav Agarwal

Reputation: 975

Notification not being displayed

I have created a broadcast receiver to receive location updates from Google Fused Location API. In my broadcast receiver, I have set up a notification to display the location coordinates. Initially, everything was working fine, however, now I am unable to get notification.

Here is my 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

Here is my BroadCast Receiver class:

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: I am testing app on Android 4.2.2, API 17. On my first few runs, notification was displayed.

EDIT: Here is my Manifest file:

<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>

Can anyone help me identify the problem????

Upvotes: 1

Views: 455

Answers (1)

Marat
Marat

Reputation: 6713

First of all add this permissions to your Manifest file:

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

Then remove <category android:name="android.intent.category.LAUNCHER"/> line and make it like this:

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

Upvotes: 1

Related Questions