public static final class drawable {
public static final int alert_dialog_icon=0x7f020000;
public static final int ic_launcher=0x7f020001;
+ public static final int wheelnotification=0x7f020002;
}
public static final class id {
public static final int ads_entry_icon=0x7f05000f;
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<level-list xmlns:android="http://schemas.android.com/apk/res/android" >
+ <item android:maxLevel="0" android:drawable="@drawable/ic_launcher" />
+ <item android:maxLevel="1" android:drawable="@drawable/alert_dialog_icon" />
+</level-list>
\ No newline at end of file
package de.android.mobiads;
import android.app.Activity;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.view.View;
public class MobiAdsMainActivity extends Activity {
+ /** For showing and hiding our notification. */
+ private NotificationManager notificationManager;
/** Messenger for communicating with service. */
Messenger mService = null;
/** Flag indicating whether we have called bind on the service. */
* Target we publish for clients to send messages to IncomingHandler.
*/
final Messenger mMessenger = new Messenger(new IncomingHandler());
-
+ /**TODO: I should use message with service to find out if the service is running instead of this booleanf field.*/
+ private boolean isEnabledService;
private static String cookie;
@Override
public void onResume() {
+ if (this.isEnabledService) {
+ this.showNotification(0);
+ }
super.onResume();
}
public void onClickStopService(View v) {
this.stopService(new Intent(MobiAdsMainActivity.this, MobiAdsService.class));
+ this.isEnabledService = false;
}
public void onClickStartService(View v) {
Intent intent = new Intent(MobiAdsMainActivity.this, MobiAdsService.class);
intent.putExtra("cookie", MobiAdsMainActivity.cookie);
+ this.notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
+ this.isEnabledService = true;
this.startService(intent);
}
setComponent(new ComponentName("de.android.mobiads", "de.android.mobiads.list.MobiAdsListActivity"));
this.startActivity(intent);
}
+
+ /**
+ * Show a notification while this service is running.
+ */
+ public void showNotification(int level) {
+
+ Intent intent = new Intent(this, MobiAdsMainActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
+ // The PendingIntent to launch our activity if the user selects this notification
+ PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+
+
+ // Set the icon, scrolling text and timestamp
+ Notification.Builder notificationBuilder = new Notification.Builder(getApplicationContext()).
+ setSmallIcon(R.drawable.wheelnotification, level).
+ setTicker(getText(R.string.remote_service_started)).
+ setWhen(System.currentTimeMillis()).
+ setContentText(getText(R.string.remote_service_started)).
+ setContentTitle(getText(R.string.remote_service_label)).
+ setContentIntent(contentIntent);
+ Notification notification = notificationBuilder.getNotification();
+ notification.flags |= Notification.FLAG_NO_CLEAR;
+
+ // Send the notification.
+ // We use a string id because it is a unique number. We use it later to cancel.
+ notificationManager.notify(R.string.remote_service_started, notification);
+ }
}
notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
// Display a notification about us starting.
- showNotification();
+ showNotification(0);
return super.onStartCommand(intent, flags, startId);
}
/**
* Show a notification while this service is running.
*/
- private void showNotification() {
- // In this sample, we'll use the same text for the ticker and the expanded notification
- CharSequence text = getText(R.string.remote_service_started);
-
- // Set the icon, scrolling text and timestamp
- Notification notification = new Notification(R.drawable.ic_launcher, text, System.currentTimeMillis());
+ public void showNotification(int level) {
Intent intent = new Intent(this, MobiAdsMainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
- Context context = getApplicationContext();
-
- //notification.contentIntent = contentIntent;
- // Set the info for the views that show in the notification panel.
- //notification.defaults |= Notification.DEFAULT_VIBRATE;
- //notification.ledARGB = 0xff00ff00;
- //notification.ledOnMS = 300;
- //notification.ledOffMS = 1000;
- //notification.flags |= Notification.FLAG_SHOW_LIGHTS;
+ // Set the icon, scrolling text and timestamp
+ Notification.Builder notificationBuilder = new Notification.Builder(getApplicationContext()).
+ setSmallIcon(R.drawable.wheelnotification, level).
+ setTicker(getText(R.string.remote_service_started)).
+ setWhen(System.currentTimeMillis()).
+ setContentText(getText(R.string.remote_service_started)).
+ setContentTitle(getText(R.string.remote_service_label)).
+ setContentIntent(contentIntent);
+ Notification notification = notificationBuilder.getNotification();
notification.flags |= Notification.FLAG_NO_CLEAR;
- notification.setLatestEventInfo(context, getText(R.string.remote_service_label), text, contentIntent);
// Send the notification.
// We use a string id because it is a unique number. We use it later to cancel.
import android.net.Uri;
import android.net.http.AndroidHttpClient;
import android.util.Log;
+import de.android.mobiads.MobiAdsService;
import de.android.mobiads.provider.Indexer;
public class MobiAdsBatch {
if ((uriInsert = updatedIndexer(objects)) != null) {
try {
downloadAds((String)objects.get("domain"), (String)objects.get("link"), (String) objects.get("id"));
+ ((MobiAdsService)MobiAdsBatch.this.context).showNotification(1);
} catch (Throwable e1) {
//In case of any error, remove the index database and the file
//or chunk successfully stored before the error.
import java.util.ArrayList;
import java.util.List;
+import de.android.mobiads.MobiAdsMainActivity;
import de.android.mobiads.R;
import de.android.mobiads.provider.Indexer;
import android.app.Activity;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Uri uri = Uri.parse(newsEntryAdapter.getItem(position).getTitle());
- startActivity( new Intent( Intent.ACTION_VIEW, uri ) );
- }
+ startActivity(new Intent(Intent.ACTION_VIEW, uri));
+ }
});
}