我不知道如何准确使用通知收件箱样式.我刚刚尝试了下面的代码,它在Notification.InboxStyle()中显示错误.我做错了什么?任何人都可以帮我解决这个问题吗?这是我的代码..
private void generateNotification(Context context, String message) {
System.out.println(message+"++++++++++2");
int icon = R.drawable.ic_message;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
String title = context.getString(R.string.message_title);
String subTitle = context.getString(R.string.message_subtitle);
Intent notificationIntent = new Intent(context, Output.class);
notificationIntent.putExtra("content", message);
PendingIntent intent = PendingIntent.getActivity(context, 0,notificationIntent, 0);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
Notification base = new Notification.Builder(context)
.setTicker(message)
.setSmallIcon(icon)
.setWhen(when)
.setContentTitle(title)
.setContentText(subTitle)
.setNumber(4)
.setContentIntent(intent)
.build();
Notification notification = new Notification.InboxStyle(base)
.addLine("First Message")
.addLine("Second Message")
.addLine("Third Message")
.addLine("Fourth Message")
.setBigContentTitle("Here Your Messages")
.setSummaryText("+3 more")
.build(); …Run Code Online (Sandbox Code Playgroud) 我正在使用android 4.4版本.如何在启动后使用广播接收器自动启动服务?提前致谢.更新:清单文件中的代码:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.prashanthi.trial.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".WordService"></service>
<receiver android:name=".MyScheduleReceiver" android:enabled="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
Run Code Online (Sandbox Code Playgroud)
接收器类中的代码:
public class MyScheduleReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Intent Detected.", Toast.LENGTH_LONG).show();
System.out.println("This is MyShedularReceiver");
Intent service = new Intent(context, WordService.class);
//service.setAction(RECEIVE_BOOT_COMPLETED);
context.startService(service);
}
}
Run Code Online (Sandbox Code Playgroud)
服务类代码:
public class WordService …Run Code Online (Sandbox Code Playgroud)