首先,我们先利用Android studio 创建一个空的应用程序。
我们还需要了解一下 apply plugin: 'com.android.application'和 apply plugin: 'com.android.library'的区别
apply plugin: 'com.android.application' -----> 应用程序的入口(个人理解。如有错,请大神指出)
apply plugin: 'com.android.library' -------> 应用程序依赖用的module 就是库(个人理解)
一般情况下,一个项目中只有一个主Module和各种依赖Module,我这里为了方便学习,同一项目下有两个应用程序即把依赖的library改成了application,这样运行下,就会安装两个程序
步骤一 (新建module和官网上不一样,官网是直接input module)
1.切换Android状态为Project状态
2.新建依赖module,命名为demo
步骤二 (在demo中导入第三方库和so文件)
1.在demo的main文件夹下新建jniLibs文件夹,并把so文件拷入
2.在demo的libs文件夹下拷入对应的jar包,然后as libraries
步骤三 (获取appkey)
1.新建demo应用程序
2.新建JMessageDemo
3.获取对应的appkey
步骤四 (在demo中的配置文件中填写配置条件,其中把配置文件下的包名改对就不会报错了 可以在配置文件中直接replace包名ok,偶尔有一两个不一样) 记得报名要改!
1.把SDK中的main下的文件考入对应module的main文件夹下,把res资源也拷入demo中的res文件夹
2.应用权限
<permission
android:name="com.example.demo.permission.JPUSH_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.demo.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"/>
<!-- 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"/>
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>
3.相关的四大组件信息
<service
android:name="cn.jpush.android.service.DownloadService"
android:enabled="true"
android:exported="false">
</service>
<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>
<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.demo"/>
</intent-filter>
</service>
<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="com.example.demo"/>
</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>
<activity
android:name="cn.jpush.android.ui.PushActivity"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
<intent-filter>
<action android:name="cn.jpush.android.ui.PushActivity"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="com.example.demo"/>
</intent-filter>
</activity>
<service
android:name="cn.jpush.android.service.DownloadService"
android:enabled="true"
android:exported="false"/>
<receiver
android:name="cn.jpush.im.android.helpers.IMReceiver"
android:enabled="true"
android:exported="false">
<intent-filter android:priority="1000">
<action android:name="cn.jpush.im.android.action.IM_RESPONSE"/>
<action android:name="cn.jpush.im.android.action.NOTIFICATION_CLICK_PROXY"/>
<category android:name="com.example.demo"/>
</intent-filter>
</receiver>
<receiver android:name="cn.jpush.android.service.AlarmReceiver"/>
<activity android:name="com.example.demo.debug.RegisterAndLoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.example.demo.debug.activity.setting.RegisterActivity"/>
<activity android:name="com.example.demo.debug.activity.setting.SettingMainActivity"/>
<activity android:name="com.example.demo.debug.activity.TypeActivity"/>
<activity android:name="com.example.demo.debug.activity.setting.InfoActivity"/>
<activity android:name="com.example.demo.debug.activity.setting.AssertEqualsActivity"/>
<activity android:name="com.example.demo.debug.activity.setting.GetUserInfoActivity"/>
<activity android:name="com.example.demo.debug.activity.setting.UpdatePassword"/>
<activity android:name="com.example.demo.debug.activity.setting.UpdateUserInfoActivity"/>
<activity android:name="com.example.demo.debug.activity.createmessage.CreateMessageActivity"/>
<activity android:name="com.example.demo.debug.activity.createmessage.CreateSigTextMessageActivity"/>
<activity android:name="com.example.demo.debug.activity.groupinfo.GroupInfoActivity"/>
<activity android:name="com.example.demo.debug.activity.groupinfo.CreateGroupActivity"/>
<activity android:name="com.example.demo.debug.activity.groupinfo.GetGroupInfoActivity"/>
<activity android:name="com.example.demo.debug.activity.imagecontent.ImageContentActivity"/>
<activity android:name="com.example.demo.debug.activity.conversation.ConversationActivity"/>
<activity android:name="com.example.demo.debug.activity.groupinfo.AddRemoveGroupMemberActivity"/>
<activity android:name="com.example.demo.debug.activity.groupinfo.UpdateGroupInfoActivity"/>
<activity android:name="com.example.demo.debug.activity.groupinfo.ExitGroupActivity"/>
<activity android:name="com.example.demo.debug.activity.groupinfo.GetLocalGroupMembersActivity"/>
<activity android:name="com.example.demo.debug.activity.createmessage.CreateGroupTextMsgActivity"/>
<activity android:name="com.example.demo.debug.activity.createmessage.CreateSigCustomMsgActivity"/>
<activity android:name="com.example.demo.debug.activity.createmessage.CreateSigImageMessageActivity"/>
<activity android:name="com.example.demo.debug.activity.createmessage.ShowMessageActivity"/>
<activity android:name="com.example.demo.debug.activity.createmessage.CreateGroupImageMsgActivity"/>
<activity android:name="com.example.demo.debug.activity.createmessage.CreateSigVoiceMsgActivity"/>
<activity android:name="com.example.demo.debug.activity.createmessage.ShowCustomMessageActivity"/>
<activity android:name="com.example.demo.debug.activity.createmessage.CreateGroupCustomMsgActivity"/>
<activity android:name="com.example.demo.debug.activity.createmessage.CreateGroupVoiceMsgActivity"/>
<activity android:name="com.example.demo.debug.activity.notify.NotifyTypeActivity"/>
<activity android:name="com.example.demo.debug.activity.setting.GetBlackListActivity"/>
<activity android:name="com.example.demo.debug.activity.setting.AddRemoveBlackListActivity"/>
<activity android:name="com.example.demo.debug.activity.setting.UpdateUserAvatar"/>
<activity android:name="com.example.demo.debug.activity.notify.ShowGroupNotificationActivity"/>
<activity android:name="com.example.demo.debug.activity.imagecontent.CreateImageContentAsyncFile"/>
<activity android:name="com.example.demo.debug.activity.imagecontent.ShowDownloadPathActivity"/>
<activity android:name="com.example.demo.debug.activity.imagecontent.CreateImageContentAsyncBitmap"/>
<activity android:name="com.example.demo.debug.activity.messagecontent.SetGetStringExtraActivity"/>
<activity android:name="com.example.demo.debug.activity.messagecontent.SetGetNumberExtraActivity"/>
<activity android:name="com.example.demo.debug.activity.messagecontent.SetGetBooleanExtraActivity"/>
<activity android:name="com.example.demo.debug.activity.messagecontent.SetGetExtraActivity"/>
<activity android:name="com.example.demo.debug.activity.createmessage.ShowDownloadVoiceInfoActivity"/>
<activity android:name="com.example.demo.debug.activity.conversation.GetConversationInfoActivity"/>
<activity android:name="com.example.demo.debug.activity.conversation.OrderMessageActivity"/>
<activity android:name="com.example.demo.debug.activity.conversation.IsShowNotifySigActivity"/>
<activity android:name="com.example.demo.debug.activity.conversation.DeleteConversationActivity"/>
<activity android:name="com.example.demo.debug.activity.setting.NoDisturbListActivity"/>
<activity android:name="com.example.demo.debug.activity.setting.ShowLogoutReasonActivity"/>
<activity android:name="com.example.demo.debug.activity.createmessage.CreateSendFileActivity"/>
<activity android:name="com.example.demo.debug.activity.friend.FriendContactManager"/>
<activity android:name="com.example.demo.debug.activity.friend.AddFriendActivity"/>
<activity android:name="com.example.demo.debug.activity.friend.ShowFriendReasonActivity"/>
<activity android:name="com.example.demo.debug.activity.createmessage.CreateLocationMessageActivity"/>
4.配置meta(就是appkey)
<meta-data
android:name="JPUSH_CHANNEL"
android:value="developer-default"/>
<meta-data
android:name="JPUSH_APPKEY"
android:value="You JPUSH_APPKEY" />
5.把demo的build.gradle 的library 改成 application
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:24.2.1'
compile files('libs/jmessage-android-1.4.2.jar')
}
步骤五 (调试运行)