2016-10-18 10 views
0

Here i am able to get this type of notification but my application stops in below 5.0. So, what can i do to have this kind of notification manager. It seems to be an error for an small image loading before the notification textアンドロイドカスタム通知問題

は、ここに私のコード

public static PendingIntent getDismissIntent(int notificationId, 
      Context context) { 
     Intent intent = new Intent(context, ClsNotificationCloseReceiver.class); 
     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 
       | Intent.FLAG_ACTIVITY_CLEAR_TASK); 
     intent.putExtra(NOTIFICATION_ID, notificationId); 
     PendingIntent dismissIntent = PendingIntent.getActivity(context, 0, 
       intent, PendingIntent.FLAG_CANCEL_CURRENT); 
     return dismissIntent; 
    } 

    private void startNotification() { 

     String ns = Context.NOTIFICATION_SERVICE; 

     notificationManager = (NotificationManager) MainActivity.this 
       .getSystemService(NOTIFICATION_SERVICE); 

     PendingIntent dismissIntent = MainActivity.getDismissIntent(1, 
       MainActivity.this); 

     @SuppressWarnings("deprecation") 
     Notification notification = new Notification(
       R.drawable.notification_icon, "abc", System.currentTimeMillis()); 

     RemoteViews notificationView = new RemoteViews(getPackageName(), 
       R.layout.mynotification); 

     // the intent that is started when the notification is clicked (works) 
     Intent intent = new Intent(MainActivity.this, MainActivity.class); 

     // PendingIntent pendingIntent = PendingIntent 
     // .getActivity(MainActivity.this, 1, intent, 
     // PendingIntent.FLAG_UPDATE_CURRENT); 

     notification.contentView = notificationView; 
     // notification.contentIntent = pendingIntent; 
     notification.flags |= Notification.FLAG_NO_CLEAR 
       | Notification.FLAG_ONGOING_EVENT; 

     // this is the intent that is supposed to be called when the 
     // button is clicked 
     Intent switchIntent = new Intent(this, MainActivity.class); 
     PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(this, 0, 
       switchIntent, 0); 

     notificationView.setOnClickPendingIntent(R.id.closeOnFlash, 
       dismissIntent); 
     notificationManager.notify(1, notification); 
    } 

mynotification.xml

<?xml version="1.0" encoding="UTF-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="center" 
    android:orientation="horizontal" 
    android:weightSum="100" > 

    <ImageView 
     android:id="@+id/notifiation_image" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="38" 
     android:contentDescription=" vvxcv" 
     android:paddingLeft="8dp" 
     android:src="@drawable/notification_icon" /> 

    <TextView 
     android:id="@+id/appName" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toEndOf="@+id/notifiation_image" 
     android:layout_toRightOf="@+id/notifiation_image" 
     android:layout_weight="57" 
     android:paddingLeft="8dp" 
     android:text="@string/app_name" 
     android:textColor="#000000" 
     android:textSize="15dp" /> 

    <Button 
     android:id="@+id/closeOnFlash" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="5" 
     android:background="@drawable/btnstop" 
     android:onClick="stopRecording" /> 

</LinearLayout> 

私はstartNotificationメソッドを呼び出していますが、それは停止しています。私はこの事をしたい:https://drive.google.com/file/d/0BwgJuKXMh_yGdG1YX1BJUUVzSTA/view?usp=sharingと私は停止ボタンを押すまで、通知はクリアされないはずです

+0

"私のアプリケーションは停止します"どのようなときにいつですか? –

+0

チェック編集質問 –

+0

あなたの代わりにNotificationCompat使用する必要があります。このように** NotificationCompat.Builder通知=新しいNotificationCompat.Builder(コンテキスト); ** –

答えて

0

まずエラーの場合にログを送信してください 私はそれだけできれいなプロジェクトの前に、その後NotificationCompat.Builderクラス&を使用して解決することができます見ての通りそれを実行します。

new NotificationCompat.Builder(getApplicationContext()); 
+0

あなたは私のコードを編集することができますしてください? –