2011-12-23 4 views
1

안드로이드에서 상태 표시 줄 알림을 설정하는 방법에 대한 조언을 해 줄 수 있습니까?Android Phonegap App - 알림을 보내는 방법

내 skillset은 모두 디자인/프론트 엔드 dev (따라서 phonegap 사용)을 기반으로하므로 이클립스의 초보자입니다.

이 튜토리얼은 http://androidforbeginners.blogspot.com/2010/02/how-to-create-status-bar-notifications.html이며 Android Manifest 파일의 활동 영역에 코드를 붙여 넣었습니다. 그러나 그것이 어떻게 작동하는지 나는 잘 모른다. 지금 이것을 APK로 컴파일하여 전화에 설치하면 알림을받을 준비가 되셨습니까? 그렇다면 어떻게 보내고 어디에서 보내는 코드를 입력해야합니까?

내 사장님이 크리스마스 전에 완성 해 주셨으면 좋겠다.

도움을 청합니다. 모두 최고 폴

답변

2

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> 
+0

감사합니다 - 내가 앱을 설치 한 사용자에게 알림을 보내 어떻게 아직도 확실히 이해 해달라고? 새 알림을 보내려고 할 때마다 업데이트 된 버전의 앱을 보내야합니까? – Dancer

+0

뭘하고 싶은지 설명해 주시겠습니까? – Yury

+0

도 - 안드로이드 SDK와 에뮬레이터를 설치했습니다. 나는 단지 내가 튜토리얼에서 언급 된 코드를 어디에 두 었는지 모른다. 새 자바 파일을 만들거나 매니페스트에 모두 들어 있습니까? 죄송합니다. 아마도이 모든 것이 아주 기본적인 것입니다 ... 일단이 서비스가 앱에 설정되면 - 어떻게 새 메시지를 보내나요? 그런데 도움을 주셔서 대단히 감사합니다! – Dancer

3

당신은 상태 표시 줄의 알림을 원하는 여기

코드가 얼마나 간단한 알림을 확인하는 것입니다? 그렇다면 ... 당신은 운이 좋다 ... 나는 이미 phonegap을 위해 만든 플러그인이다. 안드로이드에 외부 플러그인을 삽입하는 방법을 둘러보십시오. 정보 주셔서

https://github.com/phonegap/phonegap-plugins/tree/master/Android/StatusBarNotification

+0

지침은 페이지 자체에 제공됩니다. 건배!! –

+0

나는 이것을 사용한다. .. 잘 작동한다. – ghostCoder

+0

건배 Ashwarya - 멋지다. - 외부 서버에서 이러한 알림에 데이터를 푸시하는 방법도 필요 하겠지만 - 이것에 대한 아이디어는 도움이된다. Paul – Dancer

관련 문제