mirror of https://github.com/ThmmyNoLife/mTHMMY
Ezerous
8 years ago
4 changed files with 143 additions and 19 deletions
@ -0,0 +1,49 @@ |
|||
package gr.thmmy.mthmmy.receiver; |
|||
|
|||
import android.app.Notification; |
|||
import android.app.NotificationManager; |
|||
import android.content.BroadcastReceiver; |
|||
import android.content.Context; |
|||
import android.content.Intent; |
|||
import android.os.Bundle; |
|||
import android.support.v7.app.NotificationCompat; |
|||
|
|||
import gr.thmmy.mthmmy.R; |
|||
|
|||
import static gr.thmmy.mthmmy.services.DownloadService.ACTION_DOWNLOAD; |
|||
import static gr.thmmy.mthmmy.services.DownloadService.EXTRA_DOWNLOAD_ID; |
|||
import static gr.thmmy.mthmmy.services.DownloadService.EXTRA_NOTIFICATION_TEXT; |
|||
import static gr.thmmy.mthmmy.services.DownloadService.EXTRA_NOTIFICATION_TICKER; |
|||
import static gr.thmmy.mthmmy.services.DownloadService.EXTRA_NOTIFICATION_TITLE; |
|||
|
|||
public class Receiver extends BroadcastReceiver { |
|||
public Receiver() { |
|||
} |
|||
|
|||
@Override |
|||
public void onReceive(Context context, Intent intent) { |
|||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context); |
|||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); |
|||
|
|||
if(intent.getAction().equals(ACTION_DOWNLOAD)) |
|||
{ |
|||
Bundle extras = intent.getExtras(); |
|||
int id = extras.getInt(EXTRA_DOWNLOAD_ID); |
|||
String title = extras.getString(EXTRA_NOTIFICATION_TITLE); |
|||
String text =extras.getString(EXTRA_NOTIFICATION_TEXT); |
|||
String ticker =extras.getString(EXTRA_NOTIFICATION_TICKER); |
|||
|
|||
builder.setContentTitle(title) |
|||
.setContentText(text) |
|||
.setTicker(ticker) |
|||
.setAutoCancel(true) |
|||
.setSmallIcon(R.mipmap.ic_launcher) |
|||
; |
|||
|
|||
Notification notification = builder.build(); |
|||
notificationManager.notify(id, notification); |
|||
} |
|||
|
|||
} |
|||
|
|||
} |
Loading…
Reference in new issue