Skip to content

Commit

Permalink
Merge pull request #25 from archie94/target_oreo
Browse files Browse the repository at this point in the history
Target P
  • Loading branch information
dibakarece authored Dec 25, 2018
2 parents 9092201 + bb76032 commit 7af3033
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 20 deletions.
13 changes: 7 additions & 6 deletions dmaudiostreamer/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 26
compileSdkVersion 28

defaultConfig {
minSdkVersion 16
targetSdkVersion 25
targetSdkVersion 28
versionCode 2
versionName "1.0.2"

Expand All @@ -27,8 +27,9 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:mediarouter-v7:26.1.0'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.mediarouter:mediarouter:1.0.0'
api 'com.android.support:support-v4:28.0.0'
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
*/
package dm.audiostreamer;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.PendingIntent;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.media.AudioManager;
import android.media.MediaMetadataRetriever;
import android.media.RemoteControlClient;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.support.v4.app.NotificationCompat;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
Expand All @@ -27,6 +28,12 @@

import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.Objects;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;


public class AudioStreamingService extends Service implements NotificationManager.NotificationCenterDelegate {
private static final String TAG = Logger.makeLogTag(AudioStreamingService.class);
Expand Down Expand Up @@ -143,6 +150,12 @@ public void run() {

private void createNotification(MediaMetaData mSongDetail) {
try {

String channelId = "";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
channelId = getNotificationChannelId();
}

String songName = mSongDetail.getMediaTitle();
String authorName = mSongDetail.getMediaArtist();
String albumName = mSongDetail.getMediaAlbum();
Expand All @@ -157,11 +170,16 @@ private void createNotification(MediaMetaData mSongDetail) {

Notification notification = null;
if (pendingIntent != null) {
notification = new NotificationCompat.Builder(getApplicationContext()).setSmallIcon(R.drawable.player)
.setContentIntent(pendingIntent).setContentTitle(songName).build();
notification = new NotificationCompat.Builder(getApplicationContext(), channelId)
.setSmallIcon(R.drawable.player)
.setContentIntent(pendingIntent)
.setContentTitle(songName)
.build();
} else {
notification = new NotificationCompat.Builder(getApplicationContext()).setSmallIcon(R.drawable.player)
.setContentTitle(songName).build();
notification = new NotificationCompat.Builder(getApplicationContext(), channelId)
.setSmallIcon(R.drawable.player)
.setContentTitle(songName)
.build();
}

notification.contentView = simpleContentView;
Expand Down Expand Up @@ -242,24 +260,49 @@ private void createNotification(MediaMetaData mSongDetail) {
}
}

public void setListeners(RemoteViews view) {
@RequiresApi(Build.VERSION_CODES.O)
@NonNull
private String getNotificationChannelId() {
NotificationChannel channel = new NotificationChannel(TAG, getString(R.string.playback),
android.app.NotificationManager.IMPORTANCE_DEFAULT);
channel.enableLights(true);
channel.setLightColor(Color.BLUE);
channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
android.app.NotificationManager notificationManager =
(android.app.NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Objects.requireNonNull(notificationManager).createNotificationChannel(channel);
return TAG;
}

private void setListeners(RemoteViews view) {
try {
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_PREVIOUS),
PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0,
getIntentForNotification(NOTIFY_PREVIOUS), PendingIntent.FLAG_UPDATE_CURRENT);
view.setOnClickPendingIntent(R.id.player_previous, pendingIntent);
pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_CLOSE), PendingIntent.FLAG_UPDATE_CURRENT);
pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0,
getIntentForNotification(NOTIFY_CLOSE), PendingIntent.FLAG_UPDATE_CURRENT);
view.setOnClickPendingIntent(R.id.player_close, pendingIntent);
pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_PAUSE), PendingIntent.FLAG_UPDATE_CURRENT);
pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0,
getIntentForNotification(NOTIFY_PAUSE), PendingIntent.FLAG_UPDATE_CURRENT);
view.setOnClickPendingIntent(R.id.player_pause, pendingIntent);
pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_NEXT), PendingIntent.FLAG_UPDATE_CURRENT);
pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0,
getIntentForNotification(NOTIFY_NEXT), PendingIntent.FLAG_UPDATE_CURRENT);
view.setOnClickPendingIntent(R.id.player_next, pendingIntent);
pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_PLAY), PendingIntent.FLAG_UPDATE_CURRENT);
pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0,
getIntentForNotification(NOTIFY_PLAY), PendingIntent.FLAG_UPDATE_CURRENT);
view.setOnClickPendingIntent(R.id.player_play, pendingIntent);
} catch (Exception e) {
e.printStackTrace();
}
}

@NonNull
private Intent getIntentForNotification(@NonNull String action) {
Intent intent = new Intent(action);
intent.setClass(this, AudioStreamingReceiver.class);
return intent;
}

@Override
public void onDestroy() {
super.onDestroy();
Expand Down
1 change: 0 additions & 1 deletion dmaudiostreamer/src/main/java/dm/audiostreamer/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package dm.audiostreamer;


import android.support.compat.BuildConfig;
import android.util.Log;

public class Logger {
Expand Down
1 change: 1 addition & 0 deletions dmaudiostreamer/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">DMAudioStreamer</string>
<string name="playback">Playback</string>
</resources>

0 comments on commit 7af3033

Please sign in to comment.