2016-12-13 8 views
-1

Xamarin.Androidを使用してAndroidにカスタム通知を作成しようとしています。私が作成した通知は、異なるデバイスで同じものを表示しません。私は上のアプリを実行した場合のに対し通知は、rv変数を膨張させることなく、ショーです(アンドロイド4.4.2を実行します)レノボA319上でこれを実行する場合カスタム通知Androidが異なるデバイスに同じものを表示しない

Notification.Buider not = new Notification.Builder(this) 
    .SetTicker("Service started") 
    .SetContentTitle("This is the title") 
    .SetContentText("This is the content") 
    .SetSmallIcon(Resource.Drawable.Icon); 

Notification notification = not.Build(); 
notification.BigContentView=rv; 
NotificationManager manager = GetSystemService(Context.NotificationService) as NotificationManager; 
manager.Notify(0,notification); 

:これは私が使用しているコードです。 Samsung Galaxy S7(Android 6.0.1)では、rv変数のレイアウトがそれを説明しているので通知が表示されます。

通知が異なるデバイスで同じものを表示していない理由を知りたいと思います。それはアンドロイドのバージョンに起因するか、私のコードに何か問題がありますか?

Lenovo Android 4.4.2 enter image description here

+0

あなたは通知が異なるデバイスでどのように見えるかを示してもらえますか? –

+0

質問を編集しました。 –

+0

あなたの通知はどちらですか?私は最初のイメージ "これはタイトルです"を参照してください、しかし、2番目の? –

答えて

0

に通知する方法の抜粋である私はあなたのCustomLayoutを持っていないので、私は私の2 TextViewsと1つのImageViewの

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <TextView 
     android:text="Text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/text_list4_view" /> 
    <TextView 
     android:text="Text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/text_list4_view2" /> 
    <ImageView 
     android:src="@android:drawable/ic_menu_gallery" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/image_list4_view" /> 
</LinearLayout> 
と "oneimg_twolbl.xml" 作成しました

その後、私はあなたがより多くのここを見ることができます

 /////////////////////// custom notification ///////////////////////////////////// 
     RemoteViews v = new RemoteViews(PackageName, Resource.Layout.oneimg_twolbl); 
     v.SetTextViewText(Resource.Id.text_list4_view, "Text 1"); 
     v.SetTextViewText(Resource.Id.text_list4_view2, "Text 2"); 
     v.SetImageViewResource(Resource.Id.image_list4_view, Resource.Drawable.Icon); 

     NotificationCompat.Builder mBuilder = 
       new NotificationCompat.Builder(this) 
       .SetSmallIcon(Resource.Drawable.Icon) 
       .SetCustomBigContentView(v) //if API >= 16 
       .SetContent(v) 
       .SetAutoCancel(true); 

     /////////////////////// custom notification to activity call ///////////////////////////////////// 

     // Creates an explicit intent for an Activity in your app 
     Intent resultIntent = new Intent(this, this.Class); 
     // The stack builder object will contain an artificial back stack for the 
     // started Activity. 
     // This ensures that navigating backward from the Activity leads out of 
     // your application to the Home screen. 
     Android.Support.V4.App.TaskStackBuilder stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(this); 
     // Adds the back stack for the Intent (but not the Intent itself) 
     stackBuilder.AddParentStack(this.Class); 
     // Adds the Intent that starts the Activity to the top of the stack 
     stackBuilder.AddNextIntent(resultIntent); 
     PendingIntent resultPendingIntent = 
       stackBuilder.GetPendingIntent(
        0, 
        (int)PendingIntentFlags.UpdateCurrent 
       ); 
     mBuilder.SetContentIntent(resultPendingIntent); 
     /////////////////////// end custom notification to activity call ///////////////////////////////////// 

     NotificationManager mNotificationManager = 
      (NotificationManager)GetSystemService(NotificationService); 
     // count allows you to update the notification later on. 
     mNotificationManager.Notify(count++, mBuilder.Build()); 
     /////////////////////// end custom notification ///////////////////////////////////// 

によってカスタム通知としてこれを示します

enter image description here

+0

この例をありがとう!私はまた、なぜ私の通知が異なる外観を持っているかを理解しました。 Galaxy S7では通知が上部に表示され、拡張ビューモードで表示されますが、古いノートでは3番目の通知が表示されるため、拡張ビューモードではないため、64 dpの高さに制限されます。私はそれが160dpのようだと思う私のレイアウトファイルを膨らませる。通知を常に最初のものにする方法を知っていますか? –

+0

SetContentViewを呼び出さず、SetCustomBigContentViewのみを呼び出してみてください –

+0

なぜですか?これら2つの違いは何ですか?私は、SetContentViewがその標準形式で通知を表示している間に(通知が通知パネルの上にあり、したがってレイアウトが64 dpを超えて占有することがある)、SetCustomBigContentViewが拡張モードで通知を表示すると仮定します64dpより)。両者の間に他に違いはありますか? –

0

まず私は、実際のコードの代わりに、スクリーンショットを書くためにあなたをお勧めします。

第二には、ここでユーザー

private void notifyUserOfDBupdate() { 
    //Intents 
    Intent Pdf_view = new Intent(this, //class to throw the user when they hit on notification\\.class); 
    PendingIntent pdf_view = PendingIntent.getActivity(this, 0, Pdf_view, 0); 


    //Notification Manager 
    NotificationManager nm = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); 


    //The note 
    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
    Notification noti = new NotificationCompat.Builder(getApplicationContext()) 
      .setTicker("TickerTitle") 
      .setContentTitle("content title") 
      .setSound(soundUri) 
      .setContentText("content text") 
      .setContentIntent(pdf_view).getNotification(); 


    //Execution 
    noti.flags = Notification.FLAG_AUTO_CANCEL; 
    nm.notify(0, noti); 
} 
+0

ええ、これは分かっていますが、どのようにカスタム通知をすればいいですか?自分のxml(またはaxml)ファイルとそのファイルを自分の通知にするようにしたい。 –

関連する問題