/* * Copyright (c) linroid 2015. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.linroid.pushapp.util; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; import android.provider.Settings; import java.io.File; import timber.log.Timber; /** * Created by linroid on 8/18/15. */ public class IntentUtil { /** * 应用设置界面 * @param packageName */ public static Intent appInfo(String packageName) { Intent intent = new Intent(); intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts("package", packageName, null); intent.setData(uri); return intent; } /** * 安装Apk * * @param apkPath apk文件路径 */ public static Intent installApk(String apkPath) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(apkPath)), "application/vnd.android.package-archive"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); return intent; } /** * 卸载应用 * * @param packageName 包名 */ public static Intent uninstallApp(String packageName) { Uri uri = Uri.parse("package:" + packageName); Intent intent = new Intent(Intent.ACTION_DELETE, uri); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); return intent; } /** * 根据包名打开应用 * * @param packageName 包名 */ public static Intent openApp(Context context, String packageName) { PackageManager pm = context.getPackageManager(); Intent intent = pm.getLaunchIntentForPackage(packageName); if (intent != null) { intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); return intent; } else { Timber.e("未找到包名为[%s]的应用", packageName); return null; } } /** * 选择应用打开指定uri * @param uri 要打开的Uri * @return */ public static Intent openUri(String uri) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(uri)); return Intent.createChooser(intent, null); } /** * 辅助设置 * @return */ public static Intent accessibilitySettings() { Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); return intent; } }