Call missing method via reflection

Этот коммит содержится в:
Anton Tananaev
2015-09-02 19:28:47 +12:00
родитель a64da65c6f
Коммит e2d0329635
2 изменённых файлов: 16 добавлений и 4 удалений
+2 -2
Просмотреть файл
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
android { android {
compileSdkVersion 22 compileSdkVersion 23
buildToolsVersion '22.0.1' buildToolsVersion '22.0.1'
defaultConfig { defaultConfig {
minSdkVersion 3 minSdkVersion 3
targetSdkVersion 22 targetSdkVersion 23
versionCode 25 versionCode 25
versionName '3.5' versionName '3.5'
} }
+14 -2
Просмотреть файл
@@ -19,12 +19,16 @@ import android.annotation.TargetApi;
import android.app.Notification; import android.app.Notification;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.Service; import android.app.Service;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.IBinder; import android.os.IBinder;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class TrackingService extends Service { public class TrackingService extends Service {
private static final String TAG = TrackingService.class.getSimpleName(); private static final String TAG = TrackingService.class.getSimpleName();
@@ -50,8 +54,16 @@ public class TrackingService extends Service {
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification notification = new Notification(android.R.drawable.stat_notify_sync_noanim, null, 0); Notification notification = new Notification(android.R.drawable.stat_notify_sync_noanim, null, 0);
notification.setLatestEventInfo( try {
this, getString(R.string.app_name), getString(R.string.settings_status_on_summary), pendingIntent); Method method = notification.getClass().getMethod("setLatestEventInfo", Context.class, CharSequence.class, CharSequence.class, PendingIntent.class);
try {
method.invoke(notification, this, getString(R.string.app_name), getString(R.string.settings_status_on_summary), pendingIntent);
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
Log.w(TAG, e);
}
} catch (SecurityException | NoSuchMethodException e) {
Log.w(TAG, e);
}
int notificationId = NOTIFICATION_ID; int notificationId = NOTIFICATION_ID;