2017-08-10 5 views
0

私はデバイスからのすべての着信通知を読み取るアプリを持っています。小さなアイコンをbyte []に​​変換する際に問題に直面しています。どうすれば助けてくれますか?NotificationListenerServiceを使用して通知から小さなアイコンをbyte []に​​変換する方法は?

コード: -

Bundle extras = sbn.getNotification().extras; 
    String title = extras.getString("android.title"); 
    String text = extras.getCharSequence("android.text").toString(); 
    int id1 = extras.getInt(Notification.EXTRA_SMALL_ICON); 
+0

は、なぜあなたはバイト配列に変換したいのですか? –

+0

そのアプリケーションの要件 – Niraj

答えて

0
//use : 
    Context remotePackageContext = null; 
    Bitmap bmp = null; 
    try { 
     remotePackageContext = getApplicationContext().createPackageContext(pack, 0); 
     Drawable icon = remotePackageContext.getResources().getDrawable(your_id); 
     if(icon !=null) { 
      bmp = ((BitmapDrawable) icon).getBitmap(); 
     } 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 


//now convert this bitmap to byte : 

ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
      bmp.compress(Bitmap.CompressFormat.PNG, 90, baos); 
      byte[] b = baos.toByteArray(); 
+0

これは白で表示されています – Niraj

+0

私は試しています.... remotePackageContext = getApplicationContext()。createPackageContext(pack、0); 描画可能アイコン= ContextCompat.getDrawable(remotePackageContext、id1); – Niraj