Android 알림 알림 분석
4211 단어 AndroidNotification
일반적으로 Notification 을 사용 하 는 절 차 는 다음 과 같다.
시스템 알림 관리자 가 져 오기
private NotificationManager nm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//
nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}
2.주요 레이아웃 의 두 단 추 를 누 르 면 감청 이 벤트 를 추가 하고 시작 알림 을 설정 하 며 각종 속성 과 취소 알림 을 설정 합 니 다.각종 속성 코드 에 소 개 된 것 은 매우 상세 하 며,구체 적 으로 API 를 참고 할 수 있다.
시작 알림
public void send(View view){
// Activity
Intent intent = new Intent(MainActivity.this,OtherActivity.class);
//
PendingIntent pi = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);
//
Notification notify = new Notification.Builder(this)
// ,
.setAutoCancel(true)
//
.setTicker(" ")
//
.setSmallIcon(R.mipmap.ic_launcher)
//
.setContentTitle(" ")
//
.setContentText(" ")
// , led
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS)
//ALL , , , ,
// .setDefaults(ALL)
//
//setSound(Uri.parse())
//
.setContentIntent(pi)
// build
.build();
// , NotificationManager
nm.notify(1,notify);
}
여기 서 사용 하 는 Other Activity 는 알림 을 통 해 시작 하 는 또 다른 Activity 입 니 다.시작 하기 위해 서 는 목록 파일 에 이 Activity 를 추가 해 야 합 니 다.또한 플래시 와 진동기 가 사용 되 기 때문에 해당 권한 을 추가 해 야 합 니 다.
<activity android:name=".OtherActivity"> </activity>
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-permission android:name="android.permission.VIBRATE"/>
취소 알림
//
public void closed(View view){
nm.cancel(1);
}
사용 하기에 상당히 편리 합 니 다.마지막 으로 메 인 인터페이스 레이아웃 을 첨부 합 니 다.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:orientation="horizontal"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" "
android:onClick="send"
android:id="@+id/btnstartnotification"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" "
android:onClick="closed"
android:id="@+id/btnstopnotification"
/>
</LinearLayout>
이상 은 Android Notification 알림 에 대한 상세 한 내용 이 므 로 여러분 의 학습 에 도움 이 되 기 를 바 랍 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Bitrise에서 배포 어플리케이션 설정 테스트하기이 글은 Bitrise 광고 달력의 23일째 글입니다. 자체 또는 당사 등에서 Bitrise 구축 서비스를 사용합니다. 그나저나 며칠 전 Bitrise User Group Meetup #3에서 아래 슬라이드를 발표했...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.