朋友您好,我的推送通知不适用于android 5.0 lollipop,我在6.0上测试了此代码,但在5.0 huawei设备上无法正常工作,这里的代码我现在该怎么办,请帮助您解决此问题,我被困在这里步骤我几乎完成了我是初学者的所有步骤
Bitmap largeImage = BitmapFactory.decodeResource(getResources(),R.drawable.musicicon);
//Intent pauseIntent = new Intent("music.playerforandroid.ACTION_PAUSE_MUSIC");
PendingIntent pausePendingIntent = PendingIntent.getBroadcast(this, 1, new Intent("music.playerforandroid.ACTION_PAUSE_MUSIC"), 0);
PendingIntent playPendingIntent = PendingIntent.getBroadcast(this, 1, new Intent("music.playerforandroid.ACTION_PLAY_MUSIC"), 0);
PendingIntent nextPendingIntent = PendingIntent.getBroadcast(this, 1, new Intent("music.playerforandroid.NEXT_PLAY_MUSIC"), 0);
PendingIntent perviousPendingIntent = PendingIntent.getBroadcast(this, 1, new Intent("music.playerforandroid.PERVIOUS_PLAY_MUSIC"), 0);
Notification channel = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID_1)
.setSmallIcon(R.drawable.ic_music)
.setContentTitle(song.getTitle())
.setContentText(song.getArtist())
.setLargeIcon(largeImage)
.addAction(R.drawable.ic_prev, "prev", perviousPendingIntent)
.addAction(R.drawable.ic_play, "play", playPendingIntent)
.addAction(R.drawable.ic_stat_name, "pause", pausePendingIntent)
.addAction(R.drawable.ic_next, "next", nextPendingIntent)
.setStyle(new android.support.v4.media.app.NotificationCompat.MediaStyle().
setShowActionsInCompactView(1, 2, 3))
.build();
mNotificationManagerCompat.notify(1, channel);
package music.playerforandroid;
import android.app.Application;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Build;
public class App extends Application {
public static final String CHANNEL_ID_1 = "channel1";
public static final String CHANNEL_NAME_1 = "FIRSTCHANNEL";
@Override
public void onCreate() {
super.onCreate();
createNotificationChannel();
}
private void createNotificationChannel() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
NotificationChannel channle1 = new NotificationChannel(
CHANNEL_ID_1,
CHANNEL_NAME_1,
NotificationManager.IMPORTANCE_HIGH
);
channle1.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
channle1.enableLights(true);
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(channle1);
}
}
}
我收到此错误
E / MediaPlayer:应该已经设置了字幕控制器 E / MediaPlayer:应该已经设置了字幕控制器 E / AndroidRuntime:致命异常:main 进程:music.playerforandroid,PID:22269 android.app.RemoteServiceException:从包music.playerforandroid中发布的错误通知:无法针对以下项扩展RemoteViews:StatusBarNotification(pkg = music.playerforandroid user = UserHandle {0} id = 1 tag = null score = 0 key = 0 | music。 playerforandroid | 1 | null | 10112:通知(pri = 0 contentView = music.playerforandroid / 0x109007f振动=无效声音=无效默认值= 0x0标志= 0x0颜色= 0x00000000类别=传输操作= 4 vis = PRIVATE)) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1534) 在android.os.Handler.dispatchMessage(Handler.java:102) 在android.os.Looper.loop(Looper.java:135) 在android.app.ActivityThread.main(ActivityThread.java:5538) 在java.lang.reflect.Method.invoke(本机方法) 在java.lang.reflect.Method.invoke(Method.java:372) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:960) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)