नोटिफिकेशन में बड़ा आइकन (Large Icon) लगाना
setSmallIcon() अनिवार्य है (स्टेटस बार के लिए), लेकिन setLargeIcon() से दाईं ओर बड़ा आइकन (प्रोफाइल फोटो, ऐप लोगो, संपर्क फोटो) दिखा सकते हैं।
चरण 1-2: प्रोजेक्ट और लेआउट
सामान्य बटन वाला लेआउट।
चरण 3: MainActivity — Large Icon के साथ
package app.tutorialspoint.com.notifyme;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.graphics.BitmapFactory;
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("Notification Title");
mBuilder.setContentText("Content to be added");
// Large Icon सेट करें — Bitmap के रूप में
mBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_foreground));
// Small Icon अभी भी जरूरी है (स्टेटस बार, लॉक स्क्रीन के लिए)
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: मैनिफेस्ट
मानक।
Large Icon vs Small Icon
| Small Icon | Large Icon | |
|---|---|---|
| आकार | 24dp × 24dp (स्टेटस बार) | 48dp × 48dp (नोटिफिकेशन बॉडी) |
| अनिवार्य | हां | नहीं |
| उपयोग | स्टेटस बार, लॉक स्क्रीन, नोटिफिकेशन शेड हेडर | नोटिफिकेशन बॉडी में दाईं ओर (प्रोफाइल, अटैचमेंट) |
| प्रकार | मोनोक्रोम (सफेद, अल्फा चैनल) | फुल कलर बिटमैप |
| मेथड | setSmallIcon() | setLargeIcon(Bitmap) |
बिटमैप लोड करने के तरीके
BitmapFactory.decodeResource()— ड्रॉएबल रिसोर्स सेBitmapFactory.decodeStream()— इनपुट स्ट्रीम से (नेटवर्क इमेज)Glide/Picasso/Coil— लाइब्रेरी से एसिंक लोड फिर नोटिफिकेशन अपडेट करें
⚠️ ध्यान दें
लार्ज आइकन बिटमैप होता है — मेमोरी उपयोग करता है। बड़ी इमेज न दें। 48×48dp या 96×96px काफी है। नेटवर्क से लोड करने पर पहले प्लेसहोल्डर दिखाएं, फिर अपडेट करें।