极光推送——带(BroadCastReceive中消息跳转)

使用极光推送

1、极光推送频骤可参考极光官网配置进行配置需注册。
到极光官网下载SDK解压jpush-android-arm,
jpush-android-(cpu-type)-2.x.x.zip 集成压缩包内容
AndroidManifest_androidstudio_example.xml / AndroidManifest_eclipse_example.xml
客户端嵌入SDK参考的配置文件
libs/jpush-android-2.x.y.jar
SDK Java 开发包
libs/(cpu-type)/libjpush2xy.so
SDK native 开发包
res
集成SDK必须添加的资源文件
example
是一个完整的 Android 项目,通过这个演示了 JPush SDK 的基本用法,可以用来做参考。

2、SDK集成步骤

导入 SDK 开发包到你自己的应用程序项目
解压缩 jpush-android-release-2.x.y.zip 集成压缩包。
复制 libs/jpush-sdk-2.x.y.jar 到工程 libs/ 目录下。
复制 libs/(cpu-type)/libjpush2xy.so 到你的工程中存放对应cpu类型的目录下。
复制 res/ 中drawable-hdpi, raw, layout, values文件夹中的资源文件到你的工程中 res/ 对应的目录下。

如下只是配置广播中onReceive方法中的代码:可以点击推送的消息跳转到指定页面。

配置 AndroidManifest.xml

根据 SDK 压缩包里的 AndroidManifest.xml 样例文件,来配置应用程序项目的 AndroidManifest.xml 。
3、主要步骤为:
复制备注为 “Required” 的部分
将备注为替换包名的部分,替换为当前应用程序的包名
将AppKey替换为在Portal上注册该应用的的Key,例如(9fed5bcb7b9b87413678c407)

配置文件中需要配置的数据:
<permission
 android:name="您应用的包名.permission.JPUSH_MESSAGE"
 android:protectionLevel="signature" />

<!-- Required  一些系统要求的权限,如访问网络等-->
<uses-permission android:name="您应用的包名.permission.JPUSH_MESSAGE" />
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> <!-- Optional for location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />

<application
 android:icon="@drawable/ic_launcher"
 android:allowBackup="true"
 android:label="@string/app_name"
 android:name="com.example.jpushdemo.ExampleApplication">


 <!-- For test only 测试的主程序-->
 <activity
     android:name="com.example.jpushdemo.MainActivity"
     android:label="@string/app_name" >
     <intent-filter>
         <action android:name="android.intent.action.MAIN" />
         <category android:name="android.intent.category.LAUNCHER" />
     </intent-filter>
 </activity>
<!-- For test only 测试高级功能 -->
<activity android:name="com.example.jpushdemo.PushSetActivity" android:label="@string/app_name"></activity>
 <!-- For test only 测试设置 -->
<activity android:name="com.example.jpushdemo.SettingActivity" android:label="@string/app_name"></activity>
 <!-- For test only 测试状态通知栏,需要打开的Activity -->
 <activity android:name="com.example.jpushdemo.TestActivity" android:exported="false">
     <intent-filter>
         <action android:name="jpush.testAction" />
         <category android:name="jpush.testCategory" />
     </intent-filter>
 </activity>

 <!-- Rich push 核心功能 since 2.0.6-->
 <activity
     android:name="cn.jpush.android.ui.PopWinActivity"
     android:theme="@style/MyDialogStyle"
     android:exported="false">
 </activity>

 <!-- Required SDK核心功能-->
 <activity
     android:name="cn.jpush.android.ui.PushActivity"
     android:configChanges="orientation|keyboardHidden"
     android:theme="@android:style/Theme.NoTitleBar"
     android:exported="false">
     <intent-filter>
         <action android:name="cn.jpush.android.ui.PushActivity" />
         <category android:name="android.intent.category.DEFAULT" />
         <category android:name="您应用的包名" />
     </intent-filter>
 </activity>
 <!-- Required  SDK核心功能-->
 <service
     android:name="cn.jpush.android.service.DownloadService"
     android:enabled="true"
     android:exported="false" >
 </service>


 <!-- Required SDK 核心功能-->
 <!-- 可配置android:process参数将PushService放在其他进程中 -->
 <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>

 <!-- since 1.8.0 option 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 -->
 <!-- 若不启用该功能可删除该组件,将不拉起其他应用也不能被其他应用拉起 -->
 <service
     android:name="cn.jpush.android.service.DaemonService"
     android:enabled="true"
     android:exported="true">
     <intent-filter>
         <action android:name="cn.jpush.android.intent.DaemonService" />
         <category android:name="您应用的包名" />
     </intent-filter>

 </service>

 <!-- Required SDK核心功能-->
 <receiver
     android:name="cn.jpush.android.service.PushReceiver"
     android:enabled="true"
     android:exported="false">
      <intent-filter android:priority="1000">
         <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" />   <!--Required  显示通知栏 -->
         <category android:name="您应用的包名" />
     </intent-filter>
     <intent-filter>
         <action android:name="android.intent.action.USER_PRESENT" />
         <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
     </intent-filter>
      <!-- Optional -->
     <intent-filter>
         <action android:name="android.intent.action.PACKAGE_ADDED" />
         <action android:name="android.intent.action.PACKAGE_REMOVED" />
         <data android:scheme="package" />
     </intent-filter>

 </receiver>

 <!-- Required SDK核心功能-->
 <receiver android:name="cn.jpush.android.service.AlarmReceiver" android:exported="false"/>

 <!-- User defined.  For test only  用户自定义的广播接收器-->
 <receiver
     android:name="com.example.jpushdemo.MyReceiver"
     android:exported="false"
     android:enabled="true">
     <intent-filter>
         <action android:name="cn.jpush.android.intent.REGISTRATION" /> <!--Required  用户注册SDK的intent-->
         <action android:name="cn.jpush.android.intent.UNREGISTRATION" />  
         <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" /> <!--Required  用户接收SDK消息的intent-->
         <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" /> <!--Required  用户接收SDK通知栏信息的intent-->
         <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" /> <!--Required  用户打开自定义通知栏的intent-->
         <action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK" /> <!--Optional 用户接受Rich Push Javascript 回调函数的intent-->
         <action android:name="cn.jpush.android.intent.CONNECTION" /><!-- 接收网络变化 连接/断开 since 1.6.3 -->
         <category android:name="您应用的包名" />
     </intent-filter>
 </receiver>


 <!-- Required  . Enable it you can get statistics data with channel -->
 <meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
 <meta-data android:name="JPUSH_APPKEY" android:value="您应用的Appkey" /> <!--  </>值来自开发者平台取得的AppKey-->

</application>
添加代码:

init 只需要在应用程序启动时调用一次该 API 即可。
以下代码定制一个本应用程序 Application 类。

public class ExampleApplication extends Application {
@Override
        public void onCreate() {
            super.onCreate();
    JPushInterface.setDebugMode(true);
    JPushInterface.init(this);
    }
}
广播中的逻辑代码:
Bundle bundle = intent.getExtras(); 
Log.d("TAG", "onReceive - " + intent.getAction());
if(JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
//逻辑代码
}elseif(JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
System.out.println("收到了自定义消息。消息内容是:" + bundle.getString(JPushInterface.EXTRA_MESSAGE));
// 自定义消息不会展示在通知栏,完全要开发者写代码去处理
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
System.out.println("收到了通知");
// 在这里可以做些统计,或者做些其他工作
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
System.out.println("用户点击打开了通知");
// 在这里可以自己写代码去定义用户点击后的行为
Intent i = new Intent(context, SecondActivity.class);  //自定义打开的界面
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
} else {
Log.d("TAG", "Unhandled intent - " + intent.getAction());
}
}

4、配置及代码完成后,可到极光官网创建应用,填写相关信息。完成后可点击相关应用的推送,发送消息即可。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值