Skip to content

Commit d1246cd

Browse files
committed
Fix examples
We used methods no longer present in the Android API.
1 parent cae2b29 commit d1246cd

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

examples/gradle/src/main/java/org/androidannotations/sample/MyActivity.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
import org.androidannotations.annotations.res.ColorRes;
1717
import org.androidannotations.annotations.res.StringRes;
1818

19+
import android.annotation.TargetApi;
1920
import android.app.Activity;
2021
import android.app.Notification;
2122
import android.app.NotificationManager;
2223
import android.app.PendingIntent;
2324
import android.content.Intent;
2425
import android.database.sqlite.SQLiteDatabase;
26+
import android.os.Build;
2527
import android.os.Bundle;
2628
import android.util.Log;
2729
import android.view.MotionEvent;
@@ -91,11 +93,18 @@ void updateUi(String message, int color) {
9193
textView.setTextColor(color);
9294
}
9395

96+
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
9497
@UiThread(delay = 2000)
9598
void showNotificationsDelayed() {
96-
Notification notification = new Notification(R.drawable.icon, "Hello !", 0);
9799
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
98-
notification.setLatestEventInfo(getApplicationContext(), "My notification", "Hello World!", contentIntent);
100+
101+
Notification notification = new Notification.Builder(this)
102+
.setSmallIcon(R.drawable.icon)
103+
.setContentTitle("My notification")
104+
.setContentText("Hello, World!")
105+
.setContentIntent(contentIntent)
106+
.getNotification();
107+
99108
notificationManager.notify(1, notification);
100109
}
101110

@@ -121,4 +130,4 @@ int transactionalMethod(SQLiteDatabase db, int someParam) {
121130
return 42;
122131
}
123132

124-
}
133+
}

examples/maven/src/main/java/org/androidannotations/sample/MyActivity.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.util.Date;
44
import java.util.concurrent.TimeUnit;
55

6+
import android.annotation.TargetApi;
7+
import android.os.Build;
68
import org.androidannotations.annotations.Background;
79
import org.androidannotations.annotations.Click;
810
import org.androidannotations.annotations.EActivity;
@@ -92,10 +94,17 @@ void updateUi(String message, int color) {
9294
}
9395

9496
@UiThread(delay = 2000)
97+
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
9598
void showNotificationsDelayed() {
96-
Notification notification = new Notification(R.drawable.icon, "Hello !", 0);
9799
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
98-
notification.setLatestEventInfo(getApplicationContext(), "My notification", "Hello World!", contentIntent);
100+
101+
Notification notification = new Notification.Builder(this)
102+
.setSmallIcon(R.drawable.icon)
103+
.setContentTitle("My notification")
104+
.setContentText("Hello, World!")
105+
.setContentIntent(contentIntent)
106+
.getNotification();
107+
99108
notificationManager.notify(1, notification);
100109
}
101110

@@ -121,4 +130,4 @@ int transactionalMethod(SQLiteDatabase db, int someParam) {
121130
return 42;
122131
}
123132

124-
}
133+
}

0 commit comments

Comments
 (0)