우리는 게임에서 푸시 알림을 사용하여 게임이 엔진에서 일시 중지/통화 대기를 수신 할 때 특정 게임 내 물건에 대해 사용자에게 알립니다.java.lang.SecurityException from NotificationManager?
Google 개발자 콘솔에서 발생한 크래시 로그를보고 있었으며 그 중 많은 부분이 푸시 알림을 사용하여 SecurityException
에 의해 발생했습니다.
콜 스택 :
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)
그 'tinytitan'라인은 플러그인 NOTIF 우리의 자바 푸시에서입니다. 소스 코드 :
왜 우리가이 예외를 받고 해결 방법을 다음과 같다 여기
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
}
}
밖으로 매니페스트 파일입니다 (우리는 다른 플러그인을 사용하는 여러 원인이있다)?
편집 나는 매니페스트 파일의 내용을 게시 시도했지만 포맷 날을하자 않을 것이다, 그래서 나는 꺾쇠 괄호를 제거.
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"
편집 : 플러그인의 코드 나머지 :
/**
* 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();
}
C 번호에서 전화 :
TinyAndroidServices.ScheduleNotification(id, delay, title, message, true, true, true, "app_icon", androidSmallIcon);
@ main.php –
@ Hala.M 완료 허가를 공유하십시오. 제 편집을 확인하십시오. – vexe
안녕하세요, 솔루션을 찾았습니까? 나는 같은 충돌 보고서를 가지고있다 – j2esu