Android Open Source - scoreflex-android-sdk Scoreflex Broadcast Receiver






From Project

Back to project page scoreflex-android-sdk.

License

The source code is released under:

Apache License

If you think the Android project scoreflex-android-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.scoreflex;
//w ww  .  j  a v a 2  s .  c o m
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.util.Log;

public class ScoreflexBroadcastReceiver extends BroadcastReceiver {
  private static final String METADATA_ICON_KEYNAME = "notificationIcon";
  private static final String METADATA_ACTIVITY_KEYNAME = "activityName";
  
  @SuppressWarnings("unchecked")
  @Override
  public void onReceive(Context context, Intent intent) {
      ComponentName receiver = new ComponentName(context, this.getClass());
      try {
        Bundle metaData = context.getPackageManager().getReceiverInfo(receiver, PackageManager.GET_META_DATA).metaData;
        int iconId = metaData.getInt(METADATA_ICON_KEYNAME, -1); 
        String activityName = metaData.getString(METADATA_ACTIVITY_KEYNAME);
        if (iconId == -1) {
          Log.e("Scoreflex","You should specify a <meta-data android:name=\"notificationIcon\" android:resource=YourApplicationIcon/> in your Receiver definition of your AndroidMabnifest.xml");
          return;
        }
        if (activityName == null) { 
          Log.e("Scoreflex","You should specify a <meta-data android:name=\"activityName\" android:value=YourMainActivity/> in your Receiver definition of your AndroidMabnifest.xml");
          return;
        }
        ScoreflexGcmClient.onBroadcastReceived(context, intent, iconId, (Class<? extends Activity>) Class.forName(activityName));
      } catch (NameNotFoundException e) {
        e.printStackTrace();
      } catch (ClassNotFoundException e) {
        Log.e("Scoreflex","The activity you provided in  android:name=\"activityName\" doesn't exist");
        e.printStackTrace();
      }
  }

}




Java Source Code List

com.scoreflex.ConnectivityReceiver.java
com.scoreflex.QueryStringParser.java
com.scoreflex.ScoreflexActivity.java
com.scoreflex.ScoreflexBroadcastReceiver.java
com.scoreflex.ScoreflexGcmClient.java
com.scoreflex.ScoreflexJobQueue.java
com.scoreflex.ScoreflexRequestParamsDecorator.java
com.scoreflex.ScoreflexRequestVault.java
com.scoreflex.ScoreflexRestClient.java
com.scoreflex.ScoreflexUriHelper.java
com.scoreflex.ScoreflexView.java
com.scoreflex.Scoreflex.java
com.scoreflex.SocialCallback.java
com.scoreflex.SocialShareCallback.java
com.scoreflex.facebook.ScoreflexFacebookWrapper.java
com.scoreflex.google.ScoreflexGcmWrapper.java
com.scoreflex.google.ScoreflexGoogleWrapper.java
com.scoreflex.model.JSONParcelable.java