2016-07-14 2 views
1

Я создал 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. На моих первых прогонов , было отображено уведомление.

EDIT: Вот мой 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> 

Может кто-нибудь помочь мне определить проблему ????

+0

Вы включили свой LocationHandlerReceiver как '' в Manifest ? – Marat

+0

Почему вы установили приемник как ''? – Marat

+0

, чтобы позволить пользователю открывать приложение, когда он нажимает на уведомление ... однако это не имеет значения для моей проблемы. Я попытался удалить это тоже ... это была моя ошибка ... @Marat –

ответ

1

Прежде всего добавить эти разрешения на файл манифеста:

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

Затем удалите <category android:name="android.intent.category.LAUNCHER"/> линию и сделать это следующим образом:

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