------------------------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를 통해서 테스트 하면 잘 작동 합니다만..
직접 폰에다가 옴겨서 설치하니 작동 하질 않는 군요.. 리시버가 아예작동을 안하더라구요..
혹시 원인을 알고 계신분 있으신지요??...
답변 기다리겠습니다