增加微信是否安装判断
This commit is contained in:
@@ -25,6 +25,7 @@ import com.hjq.toast.Toaster;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.ttstd.elderlyassistant.bean.ContactInfo;
|
||||
import com.ttstd.elderlyassistant.config.CommonConfig;
|
||||
import com.ttstd.elderlyassistant.utils.ApkUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -119,8 +120,8 @@ public class SelectToSpeakService extends AccessibilityService {
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Log.e(TAG, "onStartCommand: ");
|
||||
if (intent != null) {
|
||||
mContact = (ContactInfo) intent.getSerializableExtra("WechatInfo");
|
||||
Log.e(TAG, "onStartCommand: wechatInfo = " + mContact);
|
||||
mContact = (ContactInfo) intent.getSerializableExtra("ContactInfo");
|
||||
Log.e(TAG, "onStartCommand: contactInfo = " + mContact);
|
||||
if (mContact != null) {
|
||||
mName = mContact.getName();
|
||||
mCallType = mContact.getOperation();
|
||||
@@ -129,7 +130,6 @@ public class SelectToSpeakService extends AccessibilityService {
|
||||
} else {
|
||||
Toaster.showLong("没有获取到联系人数据");
|
||||
}
|
||||
|
||||
}
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
@@ -301,18 +301,23 @@ public class SelectToSpeakService extends AccessibilityService {
|
||||
* 打开微信
|
||||
*/
|
||||
private void launchWeChat() {
|
||||
Intent intent = new Intent();
|
||||
ComponentName cmp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI");
|
||||
intent.setAction(Intent.ACTION_MAIN);
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
intent.setComponent(cmp);
|
||||
try {
|
||||
startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "launchWeChat: " + e.getMessage());
|
||||
if (ApkUtils.isInstalled(SelectToSpeakService.this, "com.tencent.mm")) {
|
||||
Intent intent = new Intent();
|
||||
ComponentName cmp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI");
|
||||
intent.setAction(Intent.ACTION_MAIN);
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
intent.setComponent(cmp);
|
||||
try {
|
||||
startActivity(intent);
|
||||
Toaster.show("打开微信失败,请检查微信版本是否过低");
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "launchWeChat: " + e.getMessage());
|
||||
}
|
||||
} else {
|
||||
Toaster.show("微信未安装,请安装微信后使用");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
try {
|
||||
ContactInfo contact = gson.fromJson(textRecord, type);
|
||||
Intent accessibilityIntent = new Intent(MainActivity.this, SelectToSpeakService.class);
|
||||
accessibilityIntent.putExtra("WechatInfo", contact);
|
||||
accessibilityIntent.putExtra("ContactInfo", contact);
|
||||
startService(accessibilityIntent);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "resolveIntent: " + e.getMessage());
|
||||
|
||||
@@ -139,7 +139,7 @@ public class SchemeActivity extends AppCompatActivity {
|
||||
case 3:
|
||||
case 4:
|
||||
Intent accessibilityIntent = new Intent(SchemeActivity.this, SelectToSpeakService.class);
|
||||
accessibilityIntent.putExtra("WechatInfo", contactInfo);
|
||||
accessibilityIntent.putExtra("ContactInfo", contactInfo);
|
||||
startService(accessibilityIntent);
|
||||
break;
|
||||
case 5:
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.ttstd.elderlyassistant.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
public class ApkUtils {
|
||||
|
||||
public static boolean isInstalled(Context context, String packageName) {
|
||||
if (TextUtils.isEmpty(packageName)) return false;
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
try {
|
||||
PackageInfo packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
|
||||
return packageInfo != null;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -196,9 +196,10 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:checked="@{contactInfo.operation==5}"
|
||||
android:enabled="false"
|
||||
android:maxLines="1"
|
||||
android:singleLine="true"
|
||||
android:text="拨打QQ电话" />
|
||||
android:text="拨打QQ电话(即将开放)" />
|
||||
|
||||
|
||||
<RadioButton
|
||||
@@ -206,9 +207,10 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:checked="@{contactInfo.operation==6}"
|
||||
android:enabled="false"
|
||||
android:maxLines="1"
|
||||
android:singleLine="true"
|
||||
android:text="拨打QQ视频" />
|
||||
android:text="拨打QQ视频(即将开放)" />
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user