-
Notifications
You must be signed in to change notification settings - Fork 48
/
MainActivity.java
101 lines (86 loc) · 3.02 KB
/
MainActivity.java
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
97
98
99
100
101
package com.meiqia.meiqiasdk.demo;
import android.Manifest;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.meiqia.meiqiasdk.activity.MQMessageFormActivity;
import com.meiqia.meiqiasdk.util.MQIntentBuilder;
import com.meiqia.meiqiasdk.util.MQUtils;
public class MainActivity extends Activity {
private static final int WRITE_EXTERNAL_STORAGE_REQUEST_CODE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**
* 咨询客服
*
* @param v
*/
public void conversation(View v) {
// 不兼容Android6.0动态权限
// conversation();
// 兼容Android6.0动态权限
conversationWrapper();
}
/**
* 开发者功能
*
* @param v
*/
public void developer(View v) {
startActivity(new Intent(MainActivity.this, ApiSampleActivity.class));
}
/**
* 自定义 Activity
*
* @param view
*/
public void customizedConversation(View view) {
Intent intent = new MQIntentBuilder(this, CustomizedMQConversationActivity.class).build();
startActivity(intent);
}
@TargetApi(Build.VERSION_CODES.M)
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case WRITE_EXTERNAL_STORAGE_REQUEST_CODE: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
conversationWrapper();
} else {
MQUtils.show(this, com.meiqia.meiqiasdk.R.string.mq_sdcard_no_permission);
}
break;
}
}
}
private void conversationWrapper() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
WRITE_EXTERNAL_STORAGE_REQUEST_CODE);
} else {
conversation();
}
}
private void conversation() {
Intent intent = new MQIntentBuilder(this).build();
startActivity(intent);
}
public void leaveMessageForm(View view) {
startActivity(new Intent(this, MQMessageFormActivity.class));
}
public void linkWebView(View view) {
Intent intent = new Intent(MainActivity.this, ActivityWebView.class);
intent.putExtra("link", "https://chatlink-new.meiqia.cn/widget/standalone.html?eid=ab6e3a7cda04cc8bff00237214c3bcc6");
startActivity(intent);
}
}