تعین کردن عکس نوتیفیکیشن از روی یه مسیر یا سرور
سلام به همه دوستان
در زیر من کدی که برای تولید یه نوتیفیکیشن رو استفاده میکنم آوردم.میخواستم بدونم چه جوری عکس نوتیفیکیشنم رو از آدرس یه عکس مثلا این آدرس /data/data/com.soheiljafarian.aia/Icons/ بدم؟
من تحقیق زیاد کردم میگن ظاهرا نمیشه عکس نوتیفیکیشن رو از رو رم گوشی داد و فقط از فولدر drawable میشه و ظاهرا از طریق اینترنت هم میشه.(من توی اون خط بنفش مشکل دارم)
اگر کسی میتونه بگه چه جوری عکس نوتیفیکیشنم رو از روی رم گوشی و یا سرور ( دانلود یه عکس از رو سرور رو بلدم)قرار بدم.مرسی
Intent i = new Intent(context, NotificationView.class);
i.putExtra("notificationID", notificationID);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_ONE_SHOT);
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notif = new Notification(
R.drawable.aia,
"Reminder: Meeting starts in 5 minutes",
System.currentTimeMillis());
CharSequence from = "این بازی جذاب منتشر شده است.";
CharSequence message = "بازی جهنم کلمات";
notif.setLatestEventInfo(context, from, message, pendingIntent);
nm.notify(notificationID, notif);
اول از متد زیر برای دانلود عکس استفاده کن (یا هر چیزی مثل این):
public Bitmap getBitmapFromURL(String strURL) {
try {
URL url = new URL(strURL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
و به این صورت ازش استفاده کن :
Bitmap bitmap = getBitmapFromURL("http://www.url.ir/icon.png/");
بعد از NotificationCompat.Builder در support Library برای ساختن نوتیفیکیشن استفاده کن تا روی اکثر گوشی ها کار کنه:
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
Intent notificationIntent = new Intent(getApplicationContext(), Activity.class);
// Activity.class = اکتیویتی که میخوای با کلیک روی نوتیفیکیشن باز بشه
PendingIntent pending = PendingIntent.getActivity(getApplicationContext() ,0, notificationIntent, 0);
builder.setSmallIcon(R.drawable.notification);
builder.setContentTitle("عنوان نوتیفیکیشن");
builder.setContentText("متن نوتیفیکیشن");
builder.setContentIntent(pending);
builder.setLargeIcon(bitmap);
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(0, builder.build());
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .