Skip to content

Commit

Permalink
Remove deprecated methods, use Notification.Builder
Browse files Browse the repository at this point in the history
makes MTM Android API 23 compatible, since

Notification.setLatestEventInfo(Context, CharSequence, CharSequence,
PendingIntent)

was removed with this API level.
  • Loading branch information
Flowdalic committed Jan 10, 2016
1 parent 9e30ffd commit fa3d54a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ dependencies {
}

android {
compileSdkVersion 21
compileSdkVersion 23
buildToolsVersion "21.1.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 21
targetSdkVersion 23
}

sourceSets {
Expand Down
2 changes: 1 addition & 1 deletion example/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@

android.library.reference.1=../
# Project target.
target=android-21
target=android-23
2 changes: 1 addition & 1 deletion project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@

android.library=true
# Project target.
target=android-21
target=android-23
25 changes: 16 additions & 9 deletions src/de/duenndns/ssl/MemorizingTrustManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit fa3d54a

Please sign in to comment.