关于极光推送

项目需要做了一推送的网上看到关于推送极光和个推两个比较好,极光速度快所以就用了极光了!

下载sdk解压就成了这个


这个是极光的官网:https://www.jpush.cn/common/

下载过后就是集成环境了其实不用看怎么多把上面的图片的那几个解压过后的文件拷到libs文件夹下就好了,什么三分钟啊集成啊!滚犊子吧!看着吹牛什么的,烦!

然后就是在清单文件里面,直接把开发文档里面的拷过来就好了。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.jg"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />
    <!-- Required -->
    <permission
        android:name="com.example.jg.permission.JPUSH_MESSAGE"
        android:protectionLevel="signature" />

    <!-- Required -->
    <uses-permission android:name="com.example.jg.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.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.WRITE_SETTINGS" />
    <uses-permission android:name="" />

    <!-- Optional. Required for location feature -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <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" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

    <application
        android:name="ExampleApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".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>
        <activity android:name=".TwoActivity" />

        <!-- Required SDK 核心功能 -->
        <!-- option since 2.0.5 可配置PushService,DaemonService,PushReceiver,AlarmReceiver的android:process参数 将JPush相关组件设置为一个独立进程 -->
        <!-- 如:android:process=":remote" -->
        <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=".MyBroadcastReceiver"
            android:enabled="true" >
            <intent-filter>
                <action android:name="cn.jpush.android.intent.REGISTRATION" />
                <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" />
                <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" />
                <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" />

                <category android:name="com.example.jg" />
            </intent-filter>
        </receiver>

        <!-- 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="com.example.jg" />
            </intent-filter>
        </service>

        <!-- Required -->
        <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="com.example.jg" />
            </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核心功能 -->
        <activity
            android:name="cn.jpush.android.ui.PushActivity"
            android:configChanges="orientation|keyboardHidden"
            android:exported="false" >
            <intent-filter>
                <action android:name="cn.jpush.android.ui.PushActivity" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="com.example.jg" />
            </intent-filter>
        </activity>
        <!-- Required SDK核心功能 -->
        <service
            android:name="cn.jpush.android.service.DownloadService"
            android:enabled="true"
            android:exported="false" >
        </service>
        <!-- Required SDK核心功能 -->
        <receiver android:name="cn.jpush.android.service.AlarmReceiver" />

        <!-- Required. For publish channel feature -->
        <!-- JPUSH_CHANNEL 是为了方便开发者统计APK分发渠道。 -->
        <!-- 例如: -->
        <!-- 发到 Google Play 的APK可以设置为 google-play; -->
        <!-- 发到其他市场的 APK 可以设置为 xxx-market。 -->
        <!-- 目前这个渠道统计功能的报表还未开放。 -->
        <meta-data
            android:name="JPUSH_CHANNEL"
            android:value="developer-default" />
        <!-- Required. AppKey copied from Portal -->
        <meta-data
            android:name="JPUSH_APPKEY"
            android:value="91afca9aa93e2ea8d1529ced" />
    </application>

</manifest>

上面就是我的那些清单文件了两个Activity,一个ExampleApplication就这样简单。

大家特别注意要修改包名了的com.example.jg这个是我的包名,大家换成自己的吧当然还有key;

想使用的话还是要申请一个帐号的这个大家应该都知道了的,三方就是这样的。好了大家看看我申请的:



上面那个可以就是比较重要的了,好我们开始发送消息



输入文字什么的,点击发送就可以了


好我们可以看看效果


其实这样他还是会提示我的项目叫JG,我发送的消息叫你好这个时候就成功的接收到消息了的,但是我们点击标题栏的时候并没有跳转所以极光也准备好了的在xml里面写了一个广播,当我们接收到消息我们可以通过广播来进行跳转操作:

public class MyBroadcastReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		System.out.println("来了妹儿");

		/**
		 * 默认点击了标题在跳转
		 */
		// Bundle bundle = intent.getExtras();
		// if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction()))
		// {
		// } else if (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, TwoActivity.class); // 自定义打开的界面
		// i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		// context.startActivity(i);
		// } else {
		//
		// }
		/**
		 * 默认一进来就跳转
		 */
		// intent =new Intent(context,TwoActivity.class);
		// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		// context.startActivity(intent);

	}

}
好我们的目的是跳转到 TwoActivity这里,然后就可以去推送你自己想要的了,更多高级功能请大家就参考开发文档好了。下面是 源码上传一下


da





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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值