Created
March 12, 2014 23:48
-
-
Save weitsai/9519135 to your computer and use it in GitHub Desktop.
和 UA 註冊 ID 並設定 TAG,如果有需要也可自訂 notification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package weitsai.UA.demo; | |
import com.urbanairship.AirshipConfigOptions; | |
import com.urbanairship.UAirship; | |
import com.urbanairship.push.PushManager; | |
import weitsai.UA.demo.urbanairship.UrbanairshipNotification; | |
import android.app.Application; | |
import android.content.Context; | |
import android.content.pm.PackageManager; | |
import android.content.pm.PackageManager.NameNotFoundException; | |
import java.util.HashSet; | |
import java.util.Set; | |
public class UrbanairshipApplication extends Application { | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
init(); | |
setTags(); | |
PushManager.shared().setNotificationBuilder(new UrbanairshipNotification()); | |
PushManager.shared().setIntentReceiver(IntentReceiver.class); | |
} | |
/** | |
* 設定 UA 的初始值 | |
*/ | |
private void init() { | |
AirshipConfigOptions options = AirshipConfigOptions | |
.loadDefaultOptions(UrbanairshipApplication.this); | |
options.developmentAppKey = "UA App Key"; | |
options.developmentAppSecret = "UA App Secret"; | |
options.gcmSender = "GCM Project Number"; | |
options.transport = "gcm"; | |
options.inProduction = false; // determines which app key to use | |
UAirship.takeOff(this, options); | |
} | |
/** | |
* @param isLogin | |
*/ | |
private void setTags() { | |
Set<String> tags = new HashSet<String>(); | |
PackageManager packageManger = this.getPackageManager(); | |
tags.add("begining1003@gmail.com"); | |
tags.add("android"); | |
tags.add(android.os.Build.VERSION.RELEASE); | |
try { | |
tags.add(packageManger.getPackageInfo(mContext.getPackageName(), 0).versionName); | |
} catch (NameNotFoundException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
PushManager.shared().setTags(tags); | |
PushManager.shared().setAlias("begining1003@gmail.com"); | |
PushManager.enablePush(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment