Here 알림에 대한 소스 코드를 통해 더 나은 설명을 찾을 수 있습니다.
알림은 일부 이벤트에 대한 반응 일 수 있습니다. 예를 들어 하나의 버튼으로 간단한 애플리케이션을 개발할 수 있습니다. 이 버튼을 누르면 상태 표시 줄에 알림이 표시됩니다.
개발 정보. Android SDK를 설치하고 장치의 에뮬레이터를 만들어야합니다. 또한 Android ADT를 설치하는 데 매우 유용합니다. Android 애플리케이션 개발에 도움이되는 Eclipse 용 플러그인입니다. 그런 다음 응용 프로그램을 빌드하면 자동으로 에뮬레이터에 설치됩니다.
package your.package
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class AcNotificationTestMain extends Activity implements OnClickListener {
/** Called when the activity is first created. */
private static final int SEND_ID = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button mBtnSend = (Button) findViewById(R.id.button1);
mBtnSend.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
Log.v("","OnClick...");
// Create an object of Notification manager
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int icon = android.R.drawable.sym_action_email; // icon from resources
CharSequence tickerText = "New Notification"; // ticker-text
long when = System.currentTimeMillis(); // notification time
Context context = getApplicationContext(); // application Context
CharSequence contentTitle = "My notification"; // expanded message title
CharSequence contentText = "Click me!"; // expanded message text
Intent notificationIntent = new Intent(this, AcNotificationTestMain.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
// the next two lines initialize the Notification, using the configurations above
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(SEND_ID, notification);
}
}
그리고 레이아웃 파일 :
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello"/>
<Button android:id="@+id/button1" android:text="@string/AcNotificationTest_BtnSendNotificationText" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</LinearLayout>
감사합니다 - 내가 앱을 설치 한 사용자에게 알림을 보내 어떻게 아직도 확실히 이해 해달라고? 새 알림을 보내려고 할 때마다 업데이트 된 버전의 앱을 보내야합니까? – Dancer
뭘하고 싶은지 설명해 주시겠습니까? – Yury
도 - 안드로이드 SDK와 에뮬레이터를 설치했습니다. 나는 단지 내가 튜토리얼에서 언급 된 코드를 어디에 두 었는지 모른다. 새 자바 파일을 만들거나 매니페스트에 모두 들어 있습니까? 죄송합니다. 아마도이 모든 것이 아주 기본적인 것입니다 ... 일단이 서비스가 앱에 설정되면 - 어떻게 새 메시지를 보내나요? 그런데 도움을 주셔서 대단히 감사합니다! – Dancer