2012-01-12 5 views
0

전화가 AC2M에서 푸시 알림을 받으면 알림 표시 줄에 알림이 표시되어야하고 사용자가 알림을 누르면 내 앱이 시작되어 해당 알림을 설명하는 특정 활동이 표시되어야합니다. 내 애플 리케이션의 정상적인 주먹 활동.BroadcastReceiver가 내 앱을 시작할 수 있습니까?

이 작업을 수행 할 수 있습니까? 누군가 내가 어떻게 설명 할 수 있니?

리시버를 청취하려면 앱을 시작해야합니까? 내 앱이 시작되지 않았습니까?

감사 C2DM에서

답변

1

, 그래이 가능합니다. C2DMReceiver.java 클래스 사용에

이 코드 :

@Override 
protected void onMessage(Context context, Intent intent) { 

    Bundle extras = intent.getExtras(); 
    if (extras != null) { 
     NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     int icon = R.drawable.icon;  // icon from resources 
     CharSequence tickerText = "MyApp Notification";    // ticker-text 
     long when = System.currentTimeMillis();   // notification time 
     Context context21 = getApplicationContext();  // application Context 
     CharSequence contentTitle = "MyApp Notification Title"; // expanded message title 
     CharSequence contentText = (CharSequence) extras.get("message");  // expanded message text 
    Intent notificationIntent = new Intent(this, YourActivityName.class); 
     PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); 

     Notification notification = new Notification(icon, tickerText, when); 
     notification.defaults |= Notification.DEFAULT_VIBRATE; 
     notification.defaults |= Notification.DEFAULT_LIGHTS; 
     notification.defaults |= Notification.DEFAULT_SOUND; 
     notification.flags |= Notification.FLAG_AUTO_CANCEL; 
     notification.setLatestEventInfo(context21, contentTitle, contentText, contentIntent); 
     mNotificationManager.notify(Constants.NOTIFICATION_ID, notification); 

    } 
} 

이 (기타 필요한 필요한 권한과 함께) 프로젝트의 AndroidManifest.xml에 파일에 다음과 같은 선언했는지 확인, 앱이 듣고 시작하게하려면 :

<service android:name=".C2DMReceiver" /> 

<!-- Only C2DM servers can send messages for the app. If permission is not set - any other app can generate it 


     <receiver android:name=".C2DMReceiver" android:permission="com.google.android.c2dm.permission.SEND"> --> 
      <receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver" 
       android:permission="com.google.android.c2dm.permission.SEND"> 
       <!-- Receive the actual message --> 
       <intent-filter> 
        <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
        <category android:name="com.your.packagename" /> 
       </intent-filter> 
       <!-- Receive the registration id --> 
       <intent-filter> 
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> 
        <category android:name="com.your.packagename" /> 
       </intent-filter> 
      </receiver> 
+0

아니요, 내 질문을 이해하지 못했습니다. 앱이 시작되지 않아야하며 방송 수신자가 시작해야한다고 말했습니다. 제발, 다시 읽고 대답 해주세요. – NullPointerException

+0

알림 클릭에 어떤 활동을 보이시겠습니까? 그렇지 않으면 어떻게 될까요? 설명 해주십시오. –

+0

내 앱이 시작되지 않은 상태에서 전화가 AC2M에서 푸시 알림을 받으면 알림 표시 줄에 알림이 표시되어야하고 사용자가 알림을 누르면 내 앱이 시작되고 특정 활동이 표시되어야합니다. 내 앱의 일반적인 주먹 활동이 아니라 알림을 설명합니다. – NullPointerException

관련 문제