极光推送 java 绑定别名_Android 极光推送设置别名

释放双眼,带上耳机,听听看~!

不废话,需求:服务器想向某一个用户推送消息,怎么办?

不会极光推送接入的看我之前写的如何接入极光推送的文章,

// 调用 JPush 接口来设置别名。

JPushInterface.setAliasAndTags(getApplicationContext(),

(String) msg.obj,

null,

mAliasCallback);

private final TagAliasCallback mAliasCallback = new TagAliasCallback() {

@Override

public void gotResult(int code, String alias, Set tags) {

String logs ;

switch (code) {

case 0:

logs = "Set tag and alias success";

Log.i(TAG, logs);

// 建议这里往 SharePreference 里写一个成功设置的状态。成功设置一次后,以后不必再次设置了。

break;

case 6002:

logs = "Failed to set alias and tags due to timeout. Try again after 60s.";

Log.i(TAG, logs);

// 延迟 60 秒来调用 Handler 设置别名

mHandler.sendMessageDelayed(mHa

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是 Android 使用极光推送绑定别名的代码示例: ```java import cn.jpush.android.api.JPushInterface; // 绑定别名 JPushInterface.setAlias(context, sequence, alias); // 解绑别名 JPushInterface.deleteAlias(context, sequence); ``` 其中,`context` 参数为当前上下文对象,`sequence` 参数为请求码,`alias` 参数为需要绑定别名。 注意事项: - 绑定别名时,如果已经绑定别名,则会覆盖之前的别名; - 解绑别名时,如果当前设备没有绑定别名,则不会有任何影响。 另外,在使用极光推送时,需要在 AndroidManifest.xml 文件中添加以下权限: ```xml <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="cn.jpush.android.permission.RECEIVE_MSG" /> <uses-permission android:name="cn.jpush.android.permission.READ_PHONE_STATE" /> <uses-permission android:name="cn.jpush.android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="cn.jpush.android.permission.VIBRATE" /> <uses-permission android:name="cn.jpush.android.permission.RECEIVE_BOOT_COMPLETED" /> ``` 并且,需要在 AndroidManifest.xml 文件中添加以下服务和接收器: ```xml <!-- 极光推送服务 --> <service android:name="cn.jpush.android.service.PushService" android:enabled="true" android:exported="false" > <intent-filter> <action android:name="cn.jpush.android.intent.REGISTER" /> <action android:name="cn.jpush.android.intent.REPORT" /> <action android:name="cn.jpush.android.intent.PushService" /> <action android:name="cn.jpush.android.intent.PUSH_TIME" /> </intent-filter> </service> <!-- 极光推送接收器 --> <receiver android:name="cn.jpush.android.service.PushReceiver" android:enabled="true" > <intent-filter android:priority="1000"> <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" /> <category android:name="${applicationId}" /> </intent-filter> <intent-filter> <action android:name="cn.jpush.android.intent.REGISTRATION" /> <category android:name="${applicationId}" /> </intent-filter> <intent-filter> <action android:name="cn.jpush.android.intent.UNREGISTRATION" /> <category android:name="${applicationId}" /> </intent-filter> <intent-filter> <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" /> <category android:name="${applicationId}" /> <data android:scheme="package" /> </intent-filter> <intent-filter> <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" /> <category android:name="${applicationId}" /> </intent-filter> <intent-filter> <action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK" /> <category android:name="${applicationId}" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.USER_PRESENT" /> <category android:name="${applicationId}" /> </intent-filter> <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> </intent-filter> </receiver> <!-- 极光推送唤醒接收器 --> <receiver android:name="cn.jpush.android.service.AlarmReceiver" android:enabled="true" /> ``` 以上是 Android 使用极光推送绑定别名的代码示例及注意事项。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值