InboxStyle से नोटिफिकेशन स्टाइल करना
यह आर्टिकल पिछले वाले (ID 1005061569) के समान है — दोनों NotificationCompat.InboxStyle समझाते हैं। यहां वही कोड थोड़े अलग फॉर्मेट में दिया गया है।
चरण 1-2: प्रोजेक्ट और लेआउट
पिछले आर्टिकल जैसे ही — एक बटन वाला सिंपल लेआउट।
चरण 3: MainActivity कोड
package app.tutorialspoint.com.notifyme;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
public class MainActivity extends AppCompatActivity {
public static final String NOTIFICATION_CHANNEL_ID = "10001";
private final static String default_notification_channel_id = "default";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void createNotification(View view) {
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(MainActivity.this, default_notification_channel_id);
mBuilder.setContentTitle("My Notification");
mBuilder.setStyle(new NotificationCompat.InboxStyle()
.addLine("First message line")
.addLine("Second message line")
.addLine("Third message line")
.setBigContentTitle("3 New Messages")
.setSummaryText("Tap to view all"));
mBuilder.setContentText("Notification Listener Service Example");
mBuilder.setTicker("Notification Listener Service Example");
mBuilder.setSmallIcon(R.drawable.ic_launcher_foreground);
mBuilder.setAutoCancel(true);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "NOTIFICATION_CHANNEL_NAME", importance);
mBuilder.setChannelId(NOTIFICATION_CHANNEL_ID);
assert mNotificationManager != null;
mNotificationManager.createNotificationChannel(notificationChannel);
}
assert mNotificationManager != null;
mNotificationManager.notify((int) System.currentTimeMillis(), mBuilder.build());
}
}
चरण 4: मैनिफेस्ट
पिछले आर्टिकल जैसा ही।
InboxStyle vs BigTextStyle
| फीचर | InboxStyle | BigTextStyle |
|---|---|---|
| उपयोग | कई अलग-अलग लाइनें (सूची) | एक लंबा टेक्स्ट ब्लॉक |
| मैक्स लाइनें | 5-6 | असीमित (स्क्रॉल होता है) |
| सारांश | setSummaryText() सपोर्ट | नहीं |
ईमेल, चैट ऐप्स, टास्क लिस्ट के लिए InboxStyle बेहतर है। लेख, ब्लॉग पोस्ट के लिए BigTextStyle।