From fa3d54aab3e4d5f8e252ff2c36fc0e19855a1f62 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 30 Dec 2015 23:11:15 +0100 Subject: [PATCH] Remove deprecated methods, use Notification.Builder makes MTM Android API 23 compatible, since Notification.setLatestEventInfo(Context, CharSequence, CharSequence, PendingIntent) was removed with this API level. --- build.gradle | 4 +-- example/build.gradle | 4 +-- example/project.properties | 2 +- project.properties | 2 +- .../duenndns/ssl/MemorizingTrustManager.java | 25 ++++++++++++------- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index 7c58769..86b8e9c 100644 --- a/build.gradle +++ b/build.gradle @@ -10,11 +10,11 @@ buildscript { apply plugin: 'com.android.library' android { - compileSdkVersion 21 + compileSdkVersion 23 buildToolsVersion "21.1.1" defaultConfig { minSdkVersion 7 - targetSdkVersion 21 + targetSdkVersion 23 } sourceSets { diff --git a/example/build.gradle b/example/build.gradle index bf1d91f..eafb467 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -5,11 +5,11 @@ dependencies { } android { - compileSdkVersion 21 + compileSdkVersion 23 buildToolsVersion "21.1.1" defaultConfig { minSdkVersion 7 - targetSdkVersion 21 + targetSdkVersion 23 } sourceSets { diff --git a/example/project.properties b/example/project.properties index 7d0f9c7..0fda939 100644 --- a/example/project.properties +++ b/example/project.properties @@ -9,4 +9,4 @@ android.library.reference.1=../ # Project target. -target=android-21 +target=android-23 diff --git a/project.properties b/project.properties index ca81324..cb55769 100644 --- a/project.properties +++ b/project.properties @@ -9,4 +9,4 @@ android.library=true # Project target. -target=android-21 +target=android-23 diff --git a/src/de/duenndns/ssl/MemorizingTrustManager.java b/src/de/duenndns/ssl/MemorizingTrustManager.java index cb9fc2f..1d76750 100644 --- a/src/de/duenndns/ssl/MemorizingTrustManager.java +++ b/src/de/duenndns/ssl/MemorizingTrustManager.java @@ -36,6 +36,7 @@ import android.content.Intent; import android.net.Uri; import android.util.SparseArray; +import android.os.Build; import android.os.Handler; import java.io.File; @@ -566,17 +567,23 @@ private String hostNameMessage(X509Certificate cert, String hostname) { return si.toString(); } - // We can use Notification.Builder once MTM's minSDK is >= 11 - @SuppressWarnings("deprecation") void startActivityNotification(Intent intent, int decisionId, String certName) { - Notification n = new Notification(android.R.drawable.ic_lock_lock, - master.getString(R.string.mtm_notification), - System.currentTimeMillis()); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { + LOGGER.warning("Can't fallback showing a notification. Android API level to low, requires at least 11 but was " + + Build.VERSION.SDK_INT); + return; + } + PendingIntent call = PendingIntent.getActivity(master, 0, intent, 0); - n.setLatestEventInfo(master.getApplicationContext(), - master.getString(R.string.mtm_notification), - certName, call); - n.flags |= Notification.FLAG_AUTO_CANCEL; + final Notification n = new Notification.Builder(master) + .setContentTitle(master.getString(R.string.mtm_notification)) + .setContentText(certName) + .setTicker(certName) + .setSmallIcon(android.R.drawable.ic_lock_lock) + .setWhen(System.currentTimeMillis()) + .setContentIntent(call) + .setAutoCancel(true) + .build(); notificationManager.notify(NOTIFICATION_ID + decisionId, n); }