2017-09-18 8 views
1

Wir verwenden Push-Benachrichtigungen in unserem Spiel, um Benutzer über bestimmte Ingame-Dinge zu informieren, wenn das Spiel einen Pause/Suspend-Aufruf von der Engine erhält.java.lang.SecurityException von NotificationManager?

Ich habe in der Google Developer Console nach Crash-Protokollen gesucht, und eine große Anzahl von ihnen wird durch eine SecurityException aus der Verwendung von Push-Benachrichtigungen verursacht.

Bezeichnen Sie Stapel:

java.lang.RuntimeException: 

    at android.app.ActivityThread.handleReceiver (ActivityThread.java:2697) 
    at android.app.ActivityThread.access$1500 (ActivityThread.java:178) 
    at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1466) 
    at android.os.Handler.dispatchMessage (Handler.java:107) 
    at android.os.Looper.loop (Looper.java:194) 
    at android.app.ActivityThread.main (ActivityThread.java:5560) 
    at java.lang.reflect.Method.invokeNative (Native Method) 
    at java.lang.reflect.Method.invoke (Method.java:525) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:844) 
    at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:611) 
    at dalvik.system.NativeStart.main (Native Method) 

Caused by: java.lang.SecurityException: 
    at android.os.Parcel.readException (Parcel.java:1425) 
    at android.os.Parcel.readException (Parcel.java:1379) 
    at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag (INotificationManager.java:239) 
    at android.app.NotificationManager.notify (NotificationManager.java:132) 
    at android.app.NotificationManager.notify (NotificationManager.java:108) 
    at tinytitan.tinylib.NotificationPublisher.onReceive (NotificationPublisher.java:21) 
    at android.app.ActivityThread.handleReceiver (ActivityThread.java:2690) 

Das ist tinytitan 'Linie ist aus unserer Java-Push-notif Plugin. Quellcode:

package tinytitan.tinylib; 

import android.app.Notification; 
import android.app.NotificationManager; 
import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 

public class NotificationPublisher extends BroadcastReceiver { 

    public static String NOTIFICATION_ID = "notification-id"; 
    public static String NOTIFICATION = "notification"; 

    /** 
    * Called when the BroadcastReceiver is receiving an Intent 
    */ 
    public void onReceive(Context context, Intent intent) { 
     NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); 
     Notification notification = intent.getParcelableExtra(NOTIFICATION); 
     int id = intent.getIntExtra(NOTIFICATION_ID, 0); 
     notificationManager.notify(id, notification); // <-- LINE# 21 
    } 
} 

hier aus Manifest-Dateien (es gibt mehrere Ursachen wir verschiedene Plugins):

Warum bekommen wir diese Ausnahme und wie man es beheben?

EDIT Ich versuchte, die Manifest-Dateien, Inhalte zu schreiben, aber die Formatierung würde ich es nicht zulassen, so zog ich die spitzen Klammern aus.

uses-permission android:name="android.permission.INTERNET" 
uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" 
uses-permission android:name="com.android.vending.BILLING" 
uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" 
uses-permission android:name="android.permission.WAKE_LOCK" 
uses-permission android:name="android.permission.VIBRATE" 
uses-permission android:name="android.permission.GET_TASKS" 
uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" 
uses-permission android:name="com.android.vending.CHECK_LICENSE" 
uses-permission android:name="android.permission.android.permission.READ_PHONE_STATE" 
uses-permission android:name="android.permission.ACCESS_WIFI_STATE" 

EDIT: Rest des Codes des Plugins:

/** 
* Shows a Notification with a delay 
*/ 
public static void scheduleNotification(int id, long delayMs, String title, String message, boolean vibrate, boolean lightBlink, boolean sound, String largeImage, String smallImage) 
{ 
    Notification notification = getNotification(title, message, vibrate, lightBlink, sound, smallImage, largeImage); 

    Intent notificationIntent = new Intent(UnityPlayer.currentActivity, NotificationPublisher.class); 
    notificationIntent.putExtra(NotificationPublisher.NOTIFICATION_ID, id); 
    notificationIntent.putExtra(NotificationPublisher.NOTIFICATION, notification); 
    PendingIntent pendingIntent = PendingIntent.getBroadcast(UnityPlayer.currentActivity, id, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

    long futureInMillis = SystemClock.elapsedRealtime() + delayMs; 
    AlarmManager alarmManager = (AlarmManager)UnityPlayer.currentActivity.getSystemService(Context.ALARM_SERVICE); 
    alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, futureInMillis, pendingIntent); 
} 

/** 
* Cancels a notification waiting to be added to the notification query or removes a notification 
* from the notification query. 
*/ 
public static void cancelNotification(int id) 
{ 
    //Remove it from the alarm manager (if present) 
    AlarmManager am = (AlarmManager)UnityPlayer.currentActivity.getSystemService(Context.ALARM_SERVICE); 
    Intent intent = new Intent(UnityPlayer.currentActivity, NotificationPublisher.class); 
    PendingIntent pendingIntent = PendingIntent.getBroadcast(UnityPlayer.currentActivity, id, intent, PendingIntent.FLAG_UPDATE_CURRENT); 
    am.cancel(pendingIntent); 

    //remove it from the notification query (if present) 
    android.app.NotificationManager notificationManager = (android.app.NotificationManager)UnityPlayer.currentActivity.getSystemService(Context.NOTIFICATION_SERVICE); 
    notificationManager.cancel(id); 
} 

/** 
* Removes all notifications that are in the notification query 
*/ 
public static void clearAll(){ 
    android.app.NotificationManager notificationManager = (android.app.NotificationManager)UnityPlayer.currentActivity.getSystemService(Context.NOTIFICATION_SERVICE); 
    notificationManager.cancelAll(); 
} 

Der Aufruf von C#:

TinyAndroidServices.ScheduleNotification(id, delay, title, message, true, true, true, "app_icon", androidSmallIcon); 
+0

teilen Sie bitte die Erlaubnis in Ihrem Mainfest –

+0

@ Hala.M Erledigt. Bitte überprüfe meine Bearbeitung. – vexe

+0

Hallo, hast du eine Lösung gefunden? Ich habe die gleichen Absturzberichte – j2esu

Antwort

0

Sie diese Berechtigung verwenden sollten

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

N ot this:

<uses-permission android:name="android.permission.android.permission.READ_PHONE_STATE" /> 
+0

Danke für die Antwort. Ich habe diese Erlaubnis bereits. Ich habe die Berechtigungen bearbeitet, die ich verwende. – vexe

+0

Zeige dein Benachrichtigungsobjekt @vexe – shmakova

+0

Entschuldigung, ich bin mir nicht sicher, was du unter 'Benachrichtigungsobjekt' verstehe. Ich habe den Rest des Plugin-Codes veröffentlicht. Vielleicht meinst du das Ergebnis der getNotification-Funktion? – vexe

Verwandte Themen