我试图让我的通知上比API22更高的API,但更改我的通知代码
我挣扎得到它的工作,
如果我能有一个人告诉我,或告诉我什么需要改变,这将是伟大的。
我非常亲近,但每次都失败。
下面是我的代码:
public class Utils {
public static final int NOTIFY_ID1 = 1001;
public static void notifyMessage(Context context, String msg, Activity activity){
//Notification builder;
PendingIntent contentIntent = null;
NotificationManager nm;
// The NotificationManager object is required to send the notification
nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
// Message object
Intent notificationIntent = new Intent(context, activity.getClass());
// PendingIntent.getActivity(Context context, int requestCode, Intent intent, int flags)
// Used to get a pending PendingIntent,Let the Intent start a new Activity to handle the notification
contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
//Defines the content information that appears in the notification bar
int icon = R.drawable.chat;
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, msg, when);
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_SOUND; // Call the system with sound
notification.flags |= Notification.FLAG_AUTO_CANCEL; // Clicking the Clear button or clicking on the notification will automatically disappear
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.vibrate = new long[]{300, 500};
notification.setLatestEventInfo(context, "BluetoothChat", msg, contentIntent);
/* // Customize the notification style we want to display in the status bar
builder = new Notification(context);
builder.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.ic_launcher)//Set the icon in the status bar(Small icon)
.setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.i5))//Drop the drop-down list inside the icon(Big icon)
.setTicker("this is bitch!") //Set the status bar to display the information
.setWhen(System.currentTimeMillis())//Set the time to occur
.setAutoCancel(true)//The settings can be cleared
.setContentTitle("This is ContentTitle")//Set the title in the drop-down list
.setContentText("this is ContentText");//Set the context content
*/
// Get the notification object you just created
// Notification notification = builder.getNotification();//Get a Notification
// send a notification message via NotificationManger
// Parameter 1 notification ID, parameter 2 which notification to send
nm.notify(NOTIFY_ID1, notification);
}
}
当我添加:
notification.setLatestEventInfo(context, "BluetoothChat", msg, contentIntent);
我得到下面的错误:
错误:(43 21)错误:无法找到符号方法setLatestEventInfo(Context,String,Str PendingIntent)
错误:执行任务':app:compileDebugJavaWithJavac'失败。
Compilation failed; see the compiler error output for details.
我的gradle构建:
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId 'app.name'
minSdkVersion 19
targetSdkVersion 25
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
}
dependencies {
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.android.support:support-v4:25.1.1'
compile 'com.android.support:cardview-v7:25.1.1'
compile files('libs/commons-io-2.4.jar')
}
你的问题到底是什么,api级别? – Remario
你的错误日志在哪里? [mcve] –