8

मुझे सूचनाएं सही तरीके से बनाने और भेजने के साथ समस्या आ रही है। मैंने नया Lollipop 5.0 update अधिसूचना डिज़ाइन विनिर्देश यहां पढ़ा है: https://material.google.com/style/icons.html और https://material.google.com/patterns/notifications.html और मुझे एहसास है कि सही ढंग से प्रदर्शित करने के लिए आइकन को white होना चाहिए। यह ठीक है और मैं इसे पूरी तरह से समझता हूं, लेकिन मैं अपनी अधिसूचना एक तस्वीर दिखाने के लिए चाहता हूं, जो स्पष्ट रूप से सफेद नहीं हो सकता है। हालांकि, वास्तव में मुझे भ्रमित करने वाला तथ्य यह है कि जब मैं अपने फोन पर अधिसूचना प्रस्तुत करने का प्रयास करता हूं, तो सब कुछ ठीक काम करता है। यह कुछ इस तरह दिखता है:बड़ी छवि अधिसूचना के रूप में फेसबुक छवि विभिन्न फोनों पर सफेद के रूप में दिखाई देती है?

enter image description here

हालांकि, मेरे दोस्त के फोन पर, यह एक सफेद वर्ग की तरह दिखता है, कुछ इस तरह:

enter image description here

यह अजीब है, क्योंकि हम दोनों एक ही है एंड्रॉइड का संस्करण, संस्करण 6.0.1।

private class NotificationPicture extends AsyncTask<String, Void, Bitmap> { 

     Context context; 
     String userId; 
     String postId; 
     String name; 
     String notificationBody; 
     String from; 

     public NotificationPicture(Context context) { 
      super(); 
      this.context = context; 
     } 

     @Override 
     protected Bitmap doInBackground(String... params) { 
      userId = params[0]; 
      postId = params[1]; 
      name = params[2]; 
      notificationBody = params[3]; 
      from = params[4]; 
      try { 
       URL url = new URL("https://graph.facebook.com/" + userId + "/picture?type=large"); 
       HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 
       connection.setDoInput(true); 
       connection.connect(); 
       InputStream in = connection.getInputStream(); 
       Bitmap bitmap = BitmapFactory.decodeStream(in); 
       Bitmap output; 
       Rect srcRect; 
       if (bitmap.getWidth() > bitmap.getHeight()) { 
        output = Bitmap.createBitmap(bitmap.getHeight(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); 
        srcRect = new Rect((bitmap.getWidth()-bitmap.getHeight())/2, 0, bitmap.getWidth()+(bitmap.getWidth()-bitmap.getHeight())/2, bitmap.getHeight()); 
       } else { 
        output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getWidth(), Bitmap.Config.ARGB_8888); 
        srcRect = new Rect(0, (bitmap.getHeight()-bitmap.getWidth())/2, bitmap.getWidth(), bitmap.getHeight()+(bitmap.getHeight()-bitmap.getWidth())/2); 
       } 

       Canvas canvas = new Canvas(output); 
       final int color = 0xff424242; 
       final Paint paint = new Paint(); 
       final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); 

       float r; 

       if (bitmap.getWidth() > bitmap.getHeight()) { 
        r = bitmap.getHeight()/2; 
       } else { 
        r = bitmap.getWidth()/2; 
       } 

       paint.setAntiAlias(true); 
       canvas.drawARGB(0, 0, 0, 0); 
       paint.setColor(color); 
       canvas.drawCircle(r, r, r, paint); 
       paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); 
       canvas.drawBitmap(bitmap, srcRect, rect, paint); 
       return output; 
      } catch (IOException e) { 
       FirebaseCrash.report(e); 
       return null; 
      } 
     } 

     @Override 
     protected void onPostExecute(Bitmap result) { 

      super.onPostExecute(result); 
      try { 
       NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) 
         .setContentTitle(getString(R.string.app_name)) 
         .setContentText(notificationBody) 
         .setTicker(from + " has responded!") 
         .setAutoCancel(true) 
         .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) 
         .setStyle(new NotificationCompat.BigTextStyle().bigText(notificationBody)) 
         .setSmallIcon(R.drawable.ic_tabs_notification_2) 
         .setLargeIcon(result); 
       Intent resultIntent = new Intent(context, CommentsActivity.class); 
       setupPostDetails(notificationBuilder, resultIntent, postId, userId, name, context); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

build.gradle विन्यास:

compileSdkVersion 23 
buildToolsVersion "23.0.1" 
compileOptions { 
    sourceCompatibility JavaVersion.VERSION_1_7 
    targetCompatibility JavaVersion.VERSION_1_7 
} 
defaultConfig { 
    applicationId 'com.schan.tabs' 
    multiDexEnabled true 
    minSdkVersion 19 
    targetSdkVersion 23 
    versionCode 16 
    versionName "1.16" 
    signingConfig signingConfigs.Tabs 
} 

किसी को भी किसी भी विचार क्यों यह हो रहा है है, तो कुछ अंतर्दृष्टि बहुत सराहना की जाएगी यहाँ कोड मैं सूचना भेजने के लिए प्रयोग किया जाता है। मेरे पास सैमसंग एसएम-जी 9 00 वी (सैमसंग एस 5) है और मेरे दोस्त के पास एक प्लस वन फोन है जो इससे मदद करता है।

+0

https://medium.com/exploring-android/android-n-introducing-upgraded-notifications-d4dd98a7ca92#.3xrmucoq2 –

उत्तर

2

मैं आप एंड्रॉयड 6 & ऊपरी के लिए पारदर्शी पृष्ठभूमि के साथ नई अधिसूचना आइकन प्रदान की जरूरत है, तो आप इस तरह अधिसूचना पर आइकन सेट जब:

.setSmallIcon(android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP ? R.drawable.ic_notif_with_transparent_bg : R.drawable.ic_notif_current) 

आप तस्वीर दिखाना चाहते हैं तो हो सकता है आप RemoteViews

+0

हाय, हाँ मैं पूरी तरह मैं एक पारदर्शी पृष्ठभूमि की जरूरत समझते हैं, लेकिन मुझे नहीं पता देखें कि मैं जिस तस्वीर को प्रस्तुत करना चाहता हूं उसके साथ यह कैसे संभव है। मेरे पास ऐसी छवि नहीं है जिसे मैं ड्रॉइंग के रूप में संग्रहीत करना चाहता हूं। क्या आप 'रिमोट व्यू' पर विस्तार कर सकते हैं? – user1871869

+1

शायद आप रिमोट व्यू के उदाहरण के लिए इस लिंक का अनुसरण कर सकते हैं https://futurestud.io/tutorials/glide-loading-images-into-notifications-and-appwidgets। आपको अपनी सूचनाओं के लिए कस्टम लेआउट बनाने की आवश्यकता वाले दूरस्थ दृश्य – Sodiq

0

आशा उपयोग करने के लिए कोशिश कर सकते हैं यह तुम्हारी मदद करेगा:

int icon = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? R.drawable.your_logo_for_Kitkat : R.mipmap.your_logo_for_Lolipop_and_uper_version; 
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
     .setSmallIcon(icon) 
     .setContentTitle(remoteMessage.getData().get("title")) 
     .setContentText(remoteMessage.getData().get("shortDescription")) 
     .setAutoCancel(true) 
     .setSound(defaultSoundUri) 
     .setColor(Color.RED) 
     .setStyle(notiStyle) 
     .setContentIntent(pendingIntent); 

यूआरएल लोड के लिए:

private class sendNotification extends AsyncTask<String, Void, Bitmap> { 

     Context ctx; 
     String message; 

    public sendNotification(Context context) { 
     super(); 
     this.ctx = context; 
    } 

    @Override 
    protected Bitmap doInBackground(String... params) { 

     InputStream in; 
     message = params[0] + params[1]; 
     try { 

URL url = new URL(params[2]); 
     HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 
     connection.setDoInput(true); 
     connection.connect(); 
     in = connection.getInputStream(); 
     Bitmap myBitmap = BitmapFactory.decodeStream(in); 
     return myBitmap; 




     } catch (MalformedURLException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
     return null; 
    } 

    @Override 
    protected void onPostExecute(Bitmap result) { 

     super.onPostExecute(result); 
     try { 
      NotificationManager notificationManager = (NotificationManager) ctx 
        .getSystemService(Context.NOTIFICATION_SERVICE); 

      Intent intent = new Intent(ctx, NotificationsActivity.class); 
      intent.putExtra("isFromBadge", false); 


      Notification notification = new Notification.Builder(ctx) 
        .setContentTitle(
          ctx.getResources().getString(R.string.app_name)) 
        .setContentText(message) 
        .setSmallIcon(R.drawable.ic_launcher) 
        .setLargeIcon(result).build(); 

      // hide the notification after its selected 
      notification.flags |= Notification.FLAG_AUTO_CANCEL; 

      notificationManager.notify(1, notification); 

     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
} 
संबंधित मुद्दे