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 나는 정지 버튼을 누를 때까지 알림이 삭제되지해야
"내 응용 프로그램이 멈 춥니 다"어떻게 언제 언제? –
점검 질문 편집 –
대신 NotificationCompat를 사용해야합니다. ** NotificationCompat.Builder 알림 = 새로운 NotificationCompat.Builder (컨텍스트); ** –