我是靠谱客的博主 成就大侠,这篇文章主要介绍30分钟搞定个推sdk安卓客户端接入,现在分享给大家,希望可以做个参考。

所需的工具:eclipse+adt+logcat+安卓手机+联网

1、注册成为个推开发者。个推官方网站:https://dev.getui.com/dev/


2、登记应用。


接下来,填写应用详细信息,主要是icon,packagename和appname.


登记之后,点击应用列表下刚刚登记的应用"应用配置",查看APP的相关信息。


其中AppID,AppSecret,AppKey,MasterSecret等信息就是需要在项目中配置的内容,这里需要搞清楚。

3、下载集成安卓客户端sdk工具包,并解压。

下载地址是:http://www.getui.com/download/docs/getui/android/GETUI_ANDROID_SDK_2.12.4.0.zip

4、在eclipse下新建普通的android application工程。并在工程目录下新建一个libs文件夹,并将下载的sdk工具包中的资源文件文件夹下的android-support-v4.jar和GetuiSDK2.12.4.0.jar放入libs目录,无需再手动添加到classpath,会自动添加到Android Private Libraries库下,如下图所示。


自动添加到Android Private Libraries下


接下来,我们就可以进行配置和开发了。

5、配置AndroidManifest.xml文件

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.xxx.hello" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="24" android:targetSdkVersion="27" /> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.VIBRATE"/> <uses-permission android:name="android.permission.GET_TASKS"/> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> <uses-permission android:name="getui.permission.GetuiService.com.xxx.hello"/> <uses-permission android:name="android.permission.BLUETOOTH"/> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <permission android:name="getui.permission.GetuiService.com.xxx.hello" android:protectionLevel="normal"> </permission> <application 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> <!-- getui config --> <meta-data android:name="PUSH_APPID" android:value="F8xe0FkCyl7FnDFCyXkkZ8"/> <meta-data android:name="PUSH_APPKEY" android:value="IzH1lCEBfM8bjYmMVIlQs8"/> <meta-data android:name="PUSH_APPSECRET" android:value="jGbTvwWTvS93FNRUBUjuV4"/> <service android:name="com.igexin.sdk.PushService" android:exported="true" android:label="NotificationCenter" android:process=":pushservice"> <intent-filter> <action android:name="com.igexin.sdk.action.service.message"/> </intent-filter> </service> <receiver android:name="com.igexin.sdk.PushReceiver"> <intent-filter > <action android:name="android.intent.action.BOOT_COMPLETED"/> <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/> <action android:name="android.intent.action.USER_PRESENT"/> <action android:name="com.igexin.sdk.action.refreshls"/> <action android:name="android.intent.action.MEDIA_MOUNTED"/> <action android:name="android.intent.action.ACTION_POWER_CONNECTED"/> <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/> </intent-filter> </receiver> <activity android:name="com.igexin.sdk.PushActivity" android:excludeFromRecents="true" android:exported="false" android:process=":pushservice" android:taskAffinity="com.igexin.sdk.PushActivityTask" android:theme="@android:style/Theme.Translucent.NoTitleBar" /> <activity android:name="com.igexin.sdk.GActivity" android:excludeFromRecents="true" android:exported="true" android:process=":pushservice" android:taskAffinity="com.igexin.sdk.PushActivityTask" android:theme="@android:style/Theme.Translucent.NoTitleBar" /> <service android:name=".PushIntentService" /> <service android:name=".PushDemoService" android:exported="true" android:label="PushService" android:process=":pushservice"> </service> </application> </manifest>

需要注意的地方就是:权限和appid,appkey,appsecret,再就是自定义的服务。

6、将以下文件从下载的工具包中拷贝到工程对应目录下。

so文件:资源文件/so/下面三个文件夹,均放入项目libs目录下。


png文件:资源文件/res/drawable-xxx目录下的push.png文件放入项目res/drawable-xxx对应目录下。

layout文件:资源文件/res/layout/里面的getui_notification.xml放入项目res/layout/目录下。

7、MainActivity.java类文件中初始化自定义服务PushDemoService和注册自定义服务PushIntentService。

首先新建自定义服务PushDemoService.java文件继承Service类,默认什么都不用实现:

再新建自定义服务PushIntentService.java文件,继承GTIntentService类,在onReceiveClientId方法中,打印clientid,方便后续发送消息时使用。

复制代码
1
2
3
4
5
@Override public void onReceiveClientId(Context context, String clientId) { // TODO Auto-generated method stub Log.e(TAG, "onReceiveClientId -> "+"clientid="+clientId); }

MainActivity.java中方法onCreate下增加初始化和注册代码。

复制代码
1
2
3
4
5
6
7
8
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); PushManager.getInstance().initialize(this.getApplicationContext(), PushDemoService.class); PushManager.getInstance().registerPushIntentService(this.getApplicationContext(), PushIntentService.class); Log.e("MainActivity", "onCreate start"); }

到这里,代码和配置部分已经完成了,如果项目没有报错,就可以运行了。

8、运行应用连接手机测试。

连接手机之后,在logcat下看到有日志输出,这里通过过滤clientid,我们发现在PushIntentService中增加的日志,打印出来了。


接着,我们在开发者平台中创建推送,发消息给应用。


填写要发送的标题和内容,并点击"发送预览"。


在预览界面填入clientid,发送到我们的手机。


发送成功的话,手机就会收到一条消息。


9、恭喜你,完成了个推sdk安卓客户端的集成。

最后

以上就是成就大侠最近收集整理的关于30分钟搞定个推sdk安卓客户端接入的全部内容,更多相关30分钟搞定个推sdk安卓客户端接入内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(117)

评论列表共有 0 条评论

立即
投稿
返回
顶部