gpt4 book ai didi

java - NotificationCompat.BigPictureStyle 可以获取图片显示

转载 作者:行者123 更新时间:2023-11-29 08:54:03 26 4
gpt4 key购买 nike

想知道是否有人可以提供帮助,我在使用 NotificationCompat.BigPictureStyle 时遇到了一些问题 - 我不知道我是否遗漏了什么,但是除了图片之外我的通知有效..我已经包含了很多来源的大部分发生在最后..

public class OneShotAlarm extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent)
{
int z = 4; //increase this number here to the total number of affirmations
Random rand = new Random();
int y = rand.nextInt(z);

String[] s = null;
s = new String[z]; //dim
s[0] = "i am the best and you are the most amaxzing thing on ";
s[1] = "I love and approve of myself.";
s[2] = "you are the re2t";
s[3] = "you are the res3t";

String zztitle = "";
String zzrestofline = "";
String string = s[y];
StringBuffer buffer = new StringBuffer();

if (string.length() > 25){
for(int i = 0; i < string.length(); i++) {
// Set title to first 25 chars and rest of line to rest
// if((i > 0) && (i % 100) == 0) {
if(i == 25) {
zztitle = buffer.toString();
buffer = new StringBuffer();
}
// Just adds the next character to the StringBuffer.
buffer.append(string.charAt(i));
}
zzrestofline = buffer.toString();
}
else {
zztitle = s[y];
}
setNotification(context,zzrestofline,zztitle);
WakeLocker.acquire(context);
Toast.makeText(context,s[y], Toast.LENGTH_LONG).show();
WakeLocker.release();
}
private void setNotification(Context context, String zzmsg, String zztitle) {
// http://codeversed.com/expandable-notifications-android/#Custom_View

Bitmap remote_picture = null;
remote_picture = BitmapFactory.decodeResource(context.getResources(), R.drawable.retreatgoddess);

// Create the style object with BigPictureStyle subclass.
NotificationCompat.BigPictureStyle notiStyle = new NotificationCompat.BigPictureStyle();
notiStyle.setBigContentTitle("Big Picture Expanded");
notiStyle.setSummaryText("Nice big picture.");

// Add the big picture to the style.
notiStyle.bigPicture(remote_picture);

// Creates an explicit intent for an ResultActivity to receive.
Intent resultIntent = new Intent(context, MainActivity.class); // Creates an explicit intent for an Activity in your app

// This ensures that the back button follows the recommended
// convention for the back key.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

// Adds the back stack for the Intent (but not the Intent itself).
stackBuilder.addParentStack(MainActivity.class);

// Adds the Intent that starts the Activity to the top of the stack.
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(zztitle)
.setContentText(zzmsg)
.setTicker(zztitle)
.setLargeIcon(remote_picture)
.setStyle(notiStyle);

NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
int mId = 12345; // arbitrary number
mNotificationManager.notify(mId, mBuilder.build()); // mId allows you to update the notification later on.

最佳答案

您应该知道 BigPictureStyle 仅适用于 Android JellyBean (4.1.2) 及更高版本。 NotificationCompat 类负责管理与各种 Android 版本的兼容性。您在什么设备版本上测试此代码?

关于java - NotificationCompat.BigPictureStyle 可以获取图片显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21271627/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com