2017-11-26 14 views
2

サーバから受信した小さなアイコン通知を設定したい。私のアプリはアイコンをダウンロードして、このアイコンで通知を表示したい。小さなアイコン通知を動的に設定する方法

私はこの質問を見ましたが、私は答えを見つけることができません。

私のアプリはサーバーに接続され、アイコンをダウンロードしてから、サーバーからダウンロードしたアイコンで通知を表示します。その後、URLからと

+0

アプリをインストールした後にダウンロードしたアイコンを使用したいですか? – nhoxbypass

+0

はい、私のアプリはサーバに接続されており、私のアイコンをダウンロードしてから、私はアイコンをサーバからダウンロードして表示する必要があります。 – mehrdadib

答えて

0

まずダウンロードビットマップは、API 23等の使用上

Notification noti = new NotificationCompat.Builder(this) 
       .setAutoCancel(true) 
       .setContentIntent(pendingIntent) 
       .setContentTitle("UPDATE APP") 
       .setContentText(myNotificationText) 
       .setDefaults(Notification.DEFAULT_ALL) 
       .setSmallIcon(bitmap)//set myFile?? 
       .setTicker("force android update!") 
       .setWhen(triggerTime) 
       .build(); 

Updtedを

以下
Bitmap bitmap = getBitmapFromURL("Your URL"); 


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; 
    } 
} 

のようなアイコンとして設定し、小さなアイコンにビットマップを設定し

以下
notificationBuilder.setSmallIcon(Icon.createWithBitmap(yourDownloadedBitmap)); 
+0

tanks、私にチェックさせてください。 – mehrdadib

+0

@mehrdadib ok私はあなたがしたら一度更新します – Munir

+0

"Icon.createWithBitmap"のエラーがあります。アイコンとは何ですか? – mehrdadib

関連する問題