Commit 0c0bc7848872c149993641ef79389485e0bdcdaa
1 parent
f44353d0
更改为引用maven库,连接功能添加权限判断
Showing
6 changed files
with
33 additions
and
7 deletions
.idea/gradle.xml
| @@ -3,9 +3,9 @@ | @@ -3,9 +3,9 @@ | ||
| 3 | <component name="GradleSettings"> | 3 | <component name="GradleSettings"> |
| 4 | <option name="linkedExternalProjectsSettings"> | 4 | <option name="linkedExternalProjectsSettings"> |
| 5 | <GradleProjectSettings> | 5 | <GradleProjectSettings> |
| 6 | - <option name="distributionType" value="LOCAL" /> | 6 | + <option name="distributionType" value="DEFAULT_WRAPPED" /> |
| 7 | <option name="externalProjectPath" value="$PROJECT_DIR$" /> | 7 | <option name="externalProjectPath" value="$PROJECT_DIR$" /> |
| 8 | - <option name="gradleHome" value="C:\Program Files\Android\Android Studio1\gradle\gradle-3.3" /> | 8 | + <option name="gradleHome" value="C:/Program Files/Android/Android Studio1/gradle/gradle-3.3" /> |
| 9 | <option name="modules"> | 9 | <option name="modules"> |
| 10 | <set> | 10 | <set> |
| 11 | <option value="$PROJECT_DIR$" /> | 11 | <option value="$PROJECT_DIR$" /> |
.idea/modules.xml
| @@ -4,9 +4,11 @@ | @@ -4,9 +4,11 @@ | ||
| 4 | <modules> | 4 | <modules> |
| 5 | <module fileurl="file://$PROJECT_DIR$/CNChatNDemo.iml" filepath="$PROJECT_DIR$/CNChatNDemo.iml" /> | 5 | <module fileurl="file://$PROJECT_DIR$/CNChatNDemo.iml" filepath="$PROJECT_DIR$/CNChatNDemo.iml" /> |
| 6 | <module fileurl="file://$PROJECT_DIR$/CNIMDemo.iml" filepath="$PROJECT_DIR$/CNIMDemo.iml" /> | 6 | <module fileurl="file://$PROJECT_DIR$/CNIMDemo.iml" filepath="$PROJECT_DIR$/CNIMDemo.iml" /> |
| 7 | + <module fileurl="file://$PROJECT_DIR$/CNIMDemo.iml" filepath="$PROJECT_DIR$/CNIMDemo.iml" /> | ||
| 7 | <module fileurl="file://$PROJECT_DIR$/CNIMDemo23.iml" filepath="$PROJECT_DIR$/CNIMDemo23.iml" /> | 8 | <module fileurl="file://$PROJECT_DIR$/CNIMDemo23.iml" filepath="$PROJECT_DIR$/CNIMDemo23.iml" /> |
| 8 | <module fileurl="file://$PROJECT_DIR$/CNIMDemo5.iml" filepath="$PROJECT_DIR$/CNIMDemo5.iml" /> | 9 | <module fileurl="file://$PROJECT_DIR$/CNIMDemo5.iml" filepath="$PROJECT_DIR$/CNIMDemo5.iml" /> |
| 9 | <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> | 10 | <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> |
| 11 | + <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> | ||
| 10 | </modules> | 12 | </modules> |
| 11 | </component> | 13 | </component> |
| 12 | </project> | 14 | </project> |
| 13 | \ No newline at end of file | 15 | \ No newline at end of file |
app/build.gradle
| @@ -5,7 +5,7 @@ android { | @@ -5,7 +5,7 @@ android { | ||
| 5 | buildToolsVersion "25.0.0" | 5 | buildToolsVersion "25.0.0" |
| 6 | defaultConfig { | 6 | defaultConfig { |
| 7 | applicationId "com.cnlive.im" | 7 | applicationId "com.cnlive.im" |
| 8 | - minSdkVersion 15 | 8 | + minSdkVersion 16 |
| 9 | targetSdkVersion 23 | 9 | targetSdkVersion 23 |
| 10 | versionCode 1 | 10 | versionCode 1 |
| 11 | versionName "1.0" | 11 | versionName "1.0" |
| @@ -42,8 +42,9 @@ dependencies { | @@ -42,8 +42,9 @@ dependencies { | ||
| 42 | exclude group: 'com.android.support', module: 'support-annotations' | 42 | exclude group: 'com.android.support', module: 'support-annotations' |
| 43 | }) | 43 | }) |
| 44 | compile 'com.android.support:appcompat-v7:23.4.0' | 44 | compile 'com.android.support:appcompat-v7:23.4.0' |
| 45 | - compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha9' | ||
| 46 | testCompile 'junit:junit:4.12' | 45 | testCompile 'junit:junit:4.12' |
| 47 | - compile 'com.android.support:recyclerview-v7:23.0.0' | 46 | + compile 'com.android.support:recyclerview-v7:23.4.0' |
| 48 | compile 'com.github.bumptech.glide:glide:3.7.0' | 47 | compile 'com.github.bumptech.glide:glide:3.7.0' |
| 48 | + | ||
| 49 | + compile 'com.cnlive:lib_cnutil:2.0.1' | ||
| 49 | } | 50 | } |
app/libs/libcnliveutil.jar deleted
100644 → 0
No preview for this file type
app/src/main/java/com/cnlive/im/ui/MainActivity.java
| 1 | package com.cnlive.im.ui; | 1 | package com.cnlive.im.ui; |
| 2 | 2 | ||
| 3 | +import android.Manifest; | ||
| 3 | import android.content.Intent; | 4 | import android.content.Intent; |
| 5 | +import android.content.pm.PackageManager; | ||
| 6 | +import android.os.Build; | ||
| 4 | import android.os.Bundle; | 7 | import android.os.Bundle; |
| 8 | +import android.support.annotation.NonNull; | ||
| 9 | +import android.support.v4.content.ContextCompat; | ||
| 5 | import android.support.v7.app.AppCompatActivity; | 10 | import android.support.v7.app.AppCompatActivity; |
| 6 | import android.view.View; | 11 | import android.view.View; |
| 7 | import android.widget.Button; | 12 | import android.widget.Button; |
| 13 | +import android.widget.Toast; | ||
| 8 | 14 | ||
| 9 | import com.cnlive.im.R; | 15 | import com.cnlive.im.R; |
| 10 | import com.cnlive.libs.util.chat.ChatUtil; | 16 | import com.cnlive.libs.util.chat.ChatUtil; |
| @@ -14,6 +20,7 @@ import com.cnlive.libs.util.chat.base.IChat; | @@ -14,6 +20,7 @@ import com.cnlive.libs.util.chat.base.IChat; | ||
| 14 | public class MainActivity extends AppCompatActivity implements View.OnClickListener { | 20 | public class MainActivity extends AppCompatActivity implements View.OnClickListener { |
| 15 | 21 | ||
| 16 | 22 | ||
| 23 | + private static final int PERMISSION_REQUEST_CODE = 0x1001; | ||
| 17 | private Button connectedBtn; | 24 | private Button connectedBtn; |
| 18 | private Button commentBtn; | 25 | private Button commentBtn; |
| 19 | 26 | ||
| @@ -63,7 +70,23 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe | @@ -63,7 +70,23 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe | ||
| 63 | 70 | ||
| 64 | @Override | 71 | @Override |
| 65 | public void onClick(View v) { | 72 | public void onClick(View v) { |
| 66 | - ChatUtil.connect(connectListener); | 73 | + int checkCallPhonePermission = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE); |
| 74 | + if (Build.VERSION.SDK_INT >= 23 && checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) { | ||
| 75 | + requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE}, PERMISSION_REQUEST_CODE); | ||
| 76 | + }else{ | ||
| 77 | + ChatUtil.connect(connectListener); | ||
| 78 | + } | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + @Override | ||
| 82 | + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | ||
| 83 | + super.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
| 84 | + if(requestCode == PERMISSION_REQUEST_CODE) | ||
| 85 | + if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { | ||
| 86 | + ChatUtil.connect(connectListener); | ||
| 87 | + } else { | ||
| 88 | + Toast.makeText(this, "权限已被禁止,请打开读取手机状态权限,再使用此功能", Toast.LENGTH_LONG).show(); | ||
| 89 | + } | ||
| 67 | } | 90 | } |
| 68 | } | 91 | } |
| 69 | 92 |
build.gradle
| @@ -5,7 +5,7 @@ buildscript { | @@ -5,7 +5,7 @@ buildscript { | ||
| 5 | jcenter() | 5 | jcenter() |
| 6 | } | 6 | } |
| 7 | dependencies { | 7 | dependencies { |
| 8 | - classpath 'com.android.tools.build:gradle:2.3.0' | 8 | + classpath 'com.android.tools.build:gradle:2.3.3' |
| 9 | 9 | ||
| 10 | // NOTE: Do not place your application dependencies here; they belong | 10 | // NOTE: Do not place your application dependencies here; they belong |
| 11 | // in the individual module build.gradle files | 11 | // in the individual module build.gradle files |