2016-04-30 4 views
0

Hallo Freunde url belastungs Form angezeigt Layout mit benutzerdefinierten wollen und dass es große Imageview auch zur Verfügung, die Last Form url unter meinem Code istIndividuelle Benachrichtigung mit großen Imageview nicht, die ich Benachrichtigung angezeigt in Remote android

<RelativeLayout 
    android:id="@+id/rel_top" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/img" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="5dp" 
     android:src="@drawable/app_logo"/> 

    <TextView 
     android:id="@+id/noti_first" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Title" 
     android:textStyle="bold" 
     android:layout_marginLeft="5dp" 
     android:layout_toRightOf="@+id/img" 
     android:layout_alignTop="@+id/img" 
     android:textSize="@dimen/text_16" 
     /> 
    <TextView 
     android:id="@+id/noti_second" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Title" 
     android:textStyle="normal" 
     android:layout_marginLeft="5dp" 
     android:layout_below="@+id/noti_first" 
     android:layout_toRightOf="@+id/img" 
     android:textSize="@dimen/text_15" 
     /> 
    <ImageView 
     android:id="@+id/img_preview" 
     android:layout_width="match_parent" 
     android:layout_below="@+id/img" 
     android:maxHeight="100dp" 
     android:layout_marginTop="@dimen/margin_5dp" 
     android:layout_height="100dp" 
     android:src="@drawable/app_logo"/> 
</RelativeLayout> 

GCMReceiver Klasse

public class GCMReceiver extends BroadcastReceiver { 
private String TAG = GCMReceiver.class.getName(); 
private NotificationManager mNotificationManager; 

@SuppressLint("NewApi") 
@Override 
public void onReceive(Context context, Intent intent) { 
    try { 

     StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder() 
       .detectAll() 
       .penaltyLog() 
       .build(); 
     StrictMode.setThreadPolicy(policy); 

     System.out.println("Receive"); 
     String title = intent.getExtras().getString("title"); 
     String message = intent.getExtras().getString("message"); 
     String description = intent.getExtras().getString("description"); 
     String product_id = intent.getExtras().getString("product_id"); 
     String image = intent.getExtras().getString("image"); 
     String url = intent.getExtras().getString("url"); 

     Log.d("Title", title); 
     Log.d("description", description); 
     Log.d("Image", image); 
     Log.d("url", url); 
     Tags.mStringViewAllCategory = url; 
     if (title != null && title.trim().length() > 0) { 
      Random random = new Random(); 

      mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
      Intent notifyIntent = new Intent(context, ActivityCategoryViewAll.class); 
      notifyIntent.putExtra("title", title); 
      notifyIntent.putExtra("Description", description); 
      notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 

      PendingIntent contentIntent = PendingIntent.getActivity(context, random.nextInt(), notifyIntent, 0); 
      RemoteViews expandedView = new RemoteViews(context.getPackageName(), R.layout.notification_layout); 
      expandedView.setTextViewText(R.id.noti_first, title); 
      expandedView.setTextViewText(R.id.noti_second, description); 
      Bitmap bitmap = getBitmapFromURL("https://s3.amazonaws.com/atbdev/cache/product/soie-western-wear-off-white-color-top-fl-uphQF570b7bbbd6033.jpg/3c7d9ab9f983e1598d7c00c524e5d5c0"); 

      expandedView.setImageViewBitmap(R.id.img_preview, bitmap); 

      Notification notification = new NotificationCompat.Builder(context) 
        .setSmallIcon(R.drawable.app_logo) 
        .setAutoCancel(true) 
        .setContentIntent(contentIntent) 
        .setContentTitle(title).setContentText(message).build(); 
      notification.defaults |= Notification.DEFAULT_SOUND; 
      mNotificationManager.notify(random.nextInt(), notification); 
     } 
    } catch (Exception e) { 
     Log.e(TAG, "onReceive >> " + e.toString()); 
    } 
} 

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

} 

Wenn ich oben Code Benachrichtigung laufen komme perfekt, aber URL Bild keine Idee wird angezeigt, wie kann ich dieses Problem zu lösen? Ihre alle Vorschläge sind bemerkenswert.

EDIT

Notification notification = new NotificationCompat.Builder(context) 
        .setSmallIcon(R.drawable.app_logo) 
        .setAutoCancel(true) 
        .setContentIntent(contentIntent) 
        .setContent(expandedView) 
        .setContentTitle(title).setContentText(message).build(); 
      notification.defaults |= Notification.DEFAULT_SOUND; 
      mNotificationManager.notify(random.nextInt(), notification); 

Screenshots

enter image description here

+0

Sie sind nicht die 'RemoteViews' auf die' Notification' überall zu setzen. –

+0

Mike M. Welchen Weg lassen Sie mich wissen, wenn ich einen Fehler mache? –

Antwort

0

In Ihrem Code Sie Titel & Inhalt als Standard Notificatio setzen, aber für individuelle Benachrichtigung müssen Sie mit Ihrem setContent remoteView dh expandedView

Im Folgenden Code könnte Ihnen helfen

Notification notification = new NotificationCompat.Builder(context) 
       .setSmallIcon(R.drawable.app_logo) 
       .setAutoCancel(true) 
       .setContentIntent(contentIntent) 
       .setContent(expandedView).build(); 
    notification.bigContentView = expandedView; 
+0

Anki Rawat: sehe meinen Schnittteil, den ich als epr deinen Vorschlag einstelle, aber ich immer noch nicht url image –

+0

du brauchst '.setContentTitle (title) setContentText (Nachricht)' –

+0

zu benutzen, sehe meinen Editteil immer noch nicht URL erhalten image [http://pastebin.com/kT14FuaC](http://pastebin.com/kT14FuaC) –

Verwandte Themen