12
12
import android .content .ComponentName ;
13
13
import android .content .Context ;
14
14
import android .content .Intent ;
15
- import android .content .pm .ApplicationInfo ;
16
15
import android .content .pm .PackageManager ;
17
16
import android .content .SharedPreferences ;
18
17
import android .graphics .BitmapFactory ;
@@ -87,30 +86,25 @@ private void initialize(Activity activity, NotificationCallback notificationCall
87
86
if (mVisibleNotifications == null )
88
87
mVisibleNotifications = new HashSet <>();
89
88
90
- try {
91
- ApplicationInfo ai = activity .getPackageManager ().getApplicationInfo (activity .getPackageName (), PackageManager .GET_META_DATA );
92
- Bundle bundle = ai .metaData ;
93
-
94
- Boolean rescheduleOnRestart = bundle .getBoolean ("reschedule_notifications_on_restart" );
89
+ Bundle metaData = getAppMetadata ();
95
90
96
- if ( rescheduleOnRestart ) {
97
- ComponentName receiver = new ComponentName ( mContext , UnityNotificationRestartOnBootReceiver . class );
98
- PackageManager pm = mContext . getPackageManager ( );
91
+ Boolean rescheduleOnRestart = false ;
92
+ if ( metaData != null )
93
+ rescheduleOnRestart = metaData . getBoolean ( "reschedule_notifications_on_restart" , false );
99
94
100
- pm .setComponentEnabledSetting (receiver ,
101
- PackageManager .COMPONENT_ENABLED_STATE_ENABLED ,
102
- PackageManager .DONT_KILL_APP );
103
- }
95
+ if (rescheduleOnRestart ) {
96
+ ComponentName receiver = new ComponentName (mContext , UnityNotificationRestartOnBootReceiver .class );
97
+ PackageManager pm = mContext .getPackageManager ();
104
98
105
- mOpenActivity = UnityNotificationUtilities .getOpenAppActivity (mContext , false );
106
- if (mOpenActivity == null )
107
- mOpenActivity = activity .getClass ();
108
- } catch (PackageManager .NameNotFoundException e ) {
109
- Log .e (TAG_UNITY , "Failed to load meta-data, NameNotFound: " + e .getMessage ());
110
- } catch (NullPointerException e ) {
111
- Log .e (TAG_UNITY , "Failed to load meta-data, NullPointer: " + e .getMessage ());
99
+ pm .setComponentEnabledSetting (receiver ,
100
+ PackageManager .COMPONENT_ENABLED_STATE_ENABLED ,
101
+ PackageManager .DONT_KILL_APP );
112
102
}
113
103
104
+ mOpenActivity = UnityNotificationUtilities .getOpenAppActivity (mContext , false );
105
+ if (mOpenActivity == null )
106
+ mOpenActivity = activity .getClass ();
107
+
114
108
mBackgroundThread .start ();
115
109
}
116
110
@@ -136,6 +130,14 @@ public static synchronized UnityNotificationManager getNotificationManagerImpl(A
136
130
return mUnityNotificationManager ;
137
131
}
138
132
133
+ private Bundle getAppMetadata () {
134
+ try {
135
+ return mContext .getPackageManager ().getApplicationInfo (mContext .getPackageName (), PackageManager .GET_META_DATA ).metaData ;
136
+ } catch (PackageManager .NameNotFoundException e ) {
137
+ return null ;
138
+ }
139
+ }
140
+
139
141
public NotificationManager getNotificationManager () {
140
142
return (NotificationManager ) mContext .getSystemService (Context .NOTIFICATION_SERVICE );
141
143
}
0 commit comments