3
我嘗試在用戶進入或退出特定地理圍欄時發送通知。 我已經可以在用戶進入或退出地理圍欄時進行登錄。但是,如果發生這種情況,通知不會顯示有什麼我失蹤?我在manifest文件中實現了一個主題。如何在IntentService中啓動通知
我也更新了我的表現,如:
<activity
android:name=".HomeActivity"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo.Light">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
這裏是我的GeofenceIntentService,
public class GeofenceIntentService extends IntentService {
private NotificationManager mNotificationManager;
public static final int NOTIFICATION_ID = 1;
public static final String TRANSITION_INTENT_SERVICE = "ReceiveTransitionsIntentService";
public GeofenceIntentService() {
super(TRANSITION_INTENT_SERVICE);
}
@Override
protected void onHandleIntent(Intent intent) {
if (LocationClient.hasError(intent)) {
//todo error process
} else {
int transitionType = LocationClient.getGeofenceTransition(intent);
if (transitionType == Geofence.GEOFENCE_TRANSITION_ENTER ||
transitionType == Geofence.GEOFENCE_TRANSITION_EXIT) {
List<Geofence> triggerList = LocationClient.getTriggeringGeofences(intent);
for (Geofence geofence : triggerList) {
String locationId = geofence.getRequestId();
int value = transitionType;
String geofenceStatus;
if(value == 1){
Log.i("**************************************", "Entered geofence");
sendNotification("entering");
}else if(value == 2){
Log.i("**************************************", "Exiting geofence");
sendNotification("exiting");
}
}
}
}
}
private void sendNotification(String msg) {
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, HomeActivity.class), 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setContentTitle("GCM Notification")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
}
任何人有一些想法如何得到這個工作?我的主要活動課是HomeActivity。
的可能重複[?如何顯示在狀態欄通知(http://stackoverflow.com/questions/13901657/how-to-show -notification-in-status-bar) – 2015-02-24 20:07:15