마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

BroadcastReceiver를 이용한 설치 알림

0 추천

------------------------manifest------------------------
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="kr.appsol.util.calc.formcalc.skin.whitesilver"
    android:versionCode="3"
    android:versionName="2.4" >

    <uses-sdk
        android:minSdkVersion="3"
        android:targetSdkVersion="17" />

 <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.REPLACED_PACKAGES"/>
    <uses-permission android:name="android.permission.ADDED_PACKAGES"/>
    
    <application
        android:allowBackup="true"
        android:icon="@drawable/whitesilver_img_share_emblem"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

    <service 
        android:name=".NotificationService"
        android:enabled="true" />

    <receiver android:name=".PackageReceiver">
  <intent-filter>
      <action android:name="android.intent.action.PACKAGE_ADDED"/>
      <action android:name="android.intent.action.PACKAGE_REPLACED"/>
      <data android:scheme="package"/>
  </intent-filter>  
 </receiver>
 
    </application>
</manifest>


------------------------BroadcastReceiver------------------------
public class PackageReceiver extends BroadcastReceiver{
 @Override
 public void onReceive(Context context, Intent intent) {

  Intent i = new Intent(context, NotificationService.class);
  context.startService(i);
  
 }
}


------------------------Service Class------------------------
public class NotificationService extends Service {
 
 @Override
 public IBinder onBind(Intent intent) {
  // TODO Auto-generated method stub
  return null;
 }
 
 @SuppressWarnings("deprecation")
 @Override
 public void onCreate(){
   NotificationManager mNotificationManager = (NotificationManager)getSystemService( Context.NOTIFICATION_SERVICE);

   int icon = R.drawable.ic_launcher;
   CharSequence tickerText = "Hello";
   long when = System.currentTimeMillis();
   Notification notification = new Notification(icon, tickerText, when);

   Context context = getApplicationContext();
   CharSequence contentTitle = "My notification";
   CharSequence contentText = "Hello World!";
   Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("www.google.com"));
   PendingIntent contentIntent = PendingIntent.getActivity( this, 0, notificationIntent, 0);
   notification.setLatestEventInfo( context, contentTitle, contentText, contentIntent);
   notification.defaults |= Notification.DEFAULT_VIBRATE;

   mNotificationManager.notify( 7727, notification);
 }
 @Override
 public void onDestroy(){ }
}

 

 

안녕하세요?

BroadcastReceiver를 이용해서 푸시 알림을 구현하는중인데요;; 몇가지 안되는 점이 있어서 질문 남겨 봅니다.

테스트 앱은..

액티비티는 없습니다.

위 코드를 보시면 아시다시피 브로드캐스트 리시버를 통해서

설치혹은 업데이트시 서비스를 작동 시킨 후 서비스 내에서 푸시 알람을 생성하죠..

 

그런데;; 여기서 문제가 ..이클립스 avd를 통해서 테스트 하면 잘 작동 합니다만..

직접 폰에다가 옴겨서 설치하니 작동 하질 않는 군요.. 리시버가 아예작동을 안하더라구요..

혹시 원인을 알고 계신분 있으신지요??...

답변 기다리겠습니다

Ripple (810 포인트) 님이 2014년 3월 7일 질문
브로드캐스트가 서비스를 호출하는데, 브로드캐스트는 언제 호출되나요?
위에 소스에 나와있듯이 매니페스트 내에서 리시버로 등록 하였어요
앱이 추가 되거나 수정 될 때 작동하게끔...

혹시 저거 틀린건가요?......
제가 잘못알고 있었던 것인지?....................
asdasdadadds

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...