私はAndroid開発を初めて使いました。私は、彼らがジオフェンスを入力し、バッジを獲得したことをユーザーに通知するために保留中の意図を使用するジオフェンスを設定しようとしています。バッジ/アチーブメントを設定するためにGoogle Playゲームサービスを使用しています。通知をクリック可能にして、業績ページに移動します。これは私のIntentServiceです:IntentServiceからGoogleApiClientに接続
public class GeofenceService extends IntentService {
private NotificationManager mNotificationManager;
public static final String TAG = "GeofenceService";
private GoogleApiClient mGoogleApiClient;
public GeofenceService() {
super(TAG);
}
@Override
protected void onHandleIntent(Intent intent) {
GeofencingEvent event = GeofencingEvent.fromIntent(intent);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Games.API)
.addScope(Games.SCOPE_GAMES)
.build();
mGoogleApiClient.connect();
if (event.hasError()) {
//TODO handle error
} else {
int transition = event.getGeofenceTransition();
List<Geofence> geofences = event.getTriggeringGeofences();
Geofence geofence = geofences.get(0);
String requestId = geofence.getRequestId();
if (transition == Geofence.GEOFENCE_TRANSITION_ENTER) {
Log.d(TAG, "onHandleIntent: Entering geofence - " + requestId);
if (mGoogleApiClient.isConnected()){
sendNotification("+ 100");
}
} else if (transition == Geofence.GEOFENCE_TRANSITION_EXIT) {
Log.d(TAG, "onHandleIntent: Exiting Geofence - " + requestId);
}
}
}
private String getTransitionString(int transitionType) {
switch (transitionType) {
case Geofence.GEOFENCE_TRANSITION_ENTER:
return getString(R.string.geofence_transition_entered);
case Geofence.GEOFENCE_TRANSITION_EXIT:
return getString(R.string.geofence_transition_exited);
default:
return getString(R.string.unknown_geofence_transition);
}
}
private void sendNotification(String details){
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
Intent gamesIntent = Games.Achievements.getAchievementsIntent(mGoogleApiClient);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
gamesIntent, 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setContentTitle("You got a badge")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(details))
.setContentText(details)
.setSmallIcon(R.drawable.tour);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(1, mBuilder.build());
}
}
このコードは、次のエラーを私に与え、GoogleApiClientに接続することができません:
E/PopUpManagerの:ポップアップを表示するには、noコンテンツビューが使用可能。ポップアップはこのクライアントの呼び出しに応答して と表示されません。コンテンツビューを設定するには、 setViewForPopups()を使用してください。
保留中の意図からGoogleApiClientに接続するにはどうすればよいですか?また、Google Playゲームサービスの成果の意図に沿って通知をクリックできるようにするにはどうすればよいですか?
GoogleApiClient.ConnectionCallbacksを受信する方が良いかもしれません。接続が確立されると、通知が表示されます。 – Lancelot