本文整理汇总了Java中android.content.pm.PackageManager.getLaunchIntentForPackage方法的典型用法代码示例。如果您正苦于以下问题:Java PackageManager.getLaunchIntentForPackage方法的具体用法?Java PackageManager.getLaunchIntentForPackage怎么用?Java PackageManager.getLaunchIntentForPackage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.pm.PackageManager
的用法示例。
在下文中一共展示了PackageManager.getLaunchIntentForPackage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: NextLauncher
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private void NextLauncher() {
try {
PackageManager manager = getActivity().getPackageManager();
Intent intent = manager.getLaunchIntentForPackage("com.gtp.nextlauncher");
if (intent == null) {
intent = manager.getLaunchIntentForPackage("com.gtp.nextlauncher.trial");
}
Intent next = new Intent("com.gau.go.launcherex.MyThemes.mythemeaction");
next.putExtra("type", 1);
next.putExtra("pkgname", BuildConfig.APPLICATION_ID);
getActivity().sendBroadcast(next);
startActivity(intent);
} catch (Exception e) {
Toast.makeText(getActivity(), R.string.launcher_not_found, Toast.LENGTH_SHORT).show();
}
}
示例2: NavigateToOtherApplication
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public boolean NavigateToOtherApplication(
@NonNull String packageName,
boolean finish) {
PackageManager packageManager = _context.getPackageManager();
try {
Intent startAppIntent = packageManager.getLaunchIntentForPackage(packageName);
if (startAppIntent == null) {
return false;
}
startAppIntent.addCategory(Intent.CATEGORY_LAUNCHER);
_context.startActivity(startAppIntent);
if (finish) {
((Activity) _context).finish();
}
return true;
} catch (Exception e) {
_logger.Error(e.toString());
return false;
}
}
示例3: getContentIntent
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private PendingIntent getContentIntent(AppUpdateStatus entry) {
switch (entry.status) {
case UpdateAvailable:
case ReadyToInstall:
// Make sure we have an intent to install the app. If not set, we create an intent
// to open up the app details page for the app. From there, the user can hit "install"
return getAppDetailsIntent(entry.apk);
case InstallError:
return getAppErrorIntent(entry);
case Installed:
PackageManager pm = context.getPackageManager();
Intent intentObject = pm.getLaunchIntentForPackage(entry.app.packageName);
if (intentObject != null) {
return PendingIntent.getActivity(context, 0, intentObject, 0);
} else {
// Could not get launch intent, maybe not launchable, e.g. a keyboard
return getAppDetailsIntent(entry.apk);
}
}
return null;
}
示例4: startThirdApp2
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* 启动制定包名的其他应用
* http://www.jianshu.com/p/42ae7066f8f3
*
* @param packageNameStr packageName
*/
public static boolean startThirdApp2(Activity activity, String packageNameStr) {
boolean isSuccess;
if (activity == null || activity.isFinishing()) return false;
try {
PackageManager packageManager = activity.getApplicationContext().getPackageManager();
if (checkPackInfo(packageManager, packageNameStr)) {
Intent intent = packageManager.getLaunchIntentForPackage(packageNameStr);
activity.startActivity(intent);
Toast.makeText(activity, "启动" + packageNameStr, Toast.LENGTH_SHORT).show();
isSuccess = true;
} else {
isSuccess = false;
Toast.makeText(activity, "没有安装" + packageNameStr, Toast.LENGTH_SHORT).show();
}
} catch (Throwable throwable) {
throwable.printStackTrace();
isSuccess = false;
}
return isSuccess;
}
示例5: getNameOfAppsArray
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public ArrayList<String> getNameOfAppsArray() {
PackageManager pm = context.getPackageManager();
listOfAppInfo = pm.getInstalledApplications(pm.GET_META_DATA);
for(ApplicationInfo app : listOfAppInfo) {
if(pm.getLaunchIntentForPackage(app.packageName) != null) {
// apps with launcher intent
if((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1) {
// updated system apps
} else if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
// system apps
} else {
// user installed apps
nameOfAppsArray.add((String) pm.getApplicationLabel(app));
}
}
}
return nameOfAppsArray;
}
示例6: getAppLogosArray
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public ArrayList<Drawable> getAppLogosArray() {
PackageManager pm = context.getPackageManager();
listOfAppInfo = pm.getInstalledApplications(pm.GET_META_DATA);
for(ApplicationInfo app : listOfAppInfo) {
if(pm.getLaunchIntentForPackage(app.packageName) != null) {
// apps with launcher intent
if((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1) {
// updated system apps
} else if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
// system apps
} else {
// user installed apps
appLogosArray.add(app.loadIcon(pm));
}
}
}
return appLogosArray;
}
示例7: doInBackground
import android.content.pm.PackageManager; //导入方法依赖的package包/类
@Override
protected AppsItemViewHolder doInBackground(Object... params) {
PackageManager packageManager = (PackageManager) params[0];
AppsItemViewHolder holder = (AppsItemViewHolder) params[1];
try {
Intent launchIntent = packageManager.getLaunchIntentForPackage(holder.packageName);
if (launchIntent == null) {
holder.icon = packageManager.getApplicationIcon(holder.packageName);
} else {
holder.icon = packageManager.resolveActivity(launchIntent, 0).activityInfo
.loadIcon(packageManager);
}
} catch (PackageManager.NameNotFoundException e) { // NOSONAR
// do nothing
}
return holder;
}
示例8: canPreventSystemPackage
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private static boolean canPreventSystemPackage(PackageManager pm, ApplicationInfo appInfo) {
// cannot prevent launcher
if (isLauncher(pm, appInfo.packageName)) {
return false;
}
// can prevent system packages with launcher
if (pm.getLaunchIntentForPackage(appInfo.packageName) != null) {
return true;
}
if (isSystemSignaturePackage(pm, BuildConfig.APPLICATION_ID)) {
// shouldn't happen, but for some abnormal rom
return GmsUtils.isGapps(appInfo.packageName);
} else {
return !isSystemSignaturePackage(pm, appInfo.packageName);
}
}
示例9: onCreateContextMenu
import android.content.pm.PackageManager; //导入方法依赖的package包/类
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
BreventActivity activity = (BreventActivity) mFragment.getActivity();
menu.setHeaderTitle(label);
menu.add(Menu.NONE, R.string.context_menu_select, Menu.NONE,
activity.getString(R.string.context_menu_select));
menu.add(Menu.NONE, R.string.context_menu_package_name, Menu.NONE,
activity.getString(R.string.context_menu_package_name));
menu.add(Menu.NONE, R.string.context_menu_app_info, Menu.NONE,
activity.getString(R.string.context_menu_app_info));
PackageManager packageManager = mFragment.getActivity().getPackageManager();
if (BuildConfig.APPLICATION_ID.equals(packageName)) {
menu.add(Menu.NONE, R.string.context_menu_brevent_server_info, Menu.NONE,
activity.getString(R.string.context_menu_brevent_server_info));
} else if (packageManager.getLaunchIntentForPackage(packageName) != null) {
menu.add(Menu.NONE, R.string.context_menu_open, Menu.NONE,
activity.getString(R.string.context_menu_open));
}
if (activity.isBrevent(packageName)) {
if (activity.isPriority(packageName)) {
menu.add(Menu.NONE, R.string.context_menu_unset_priority, Menu.NONE,
activity.getString(R.string.context_menu_unset_priority));
} else {
menu.add(Menu.NONE, R.string.context_menu_set_priority, Menu.NONE,
activity.getString(R.string.context_menu_set_priority));
}
}
if (activity.hasOps(packageName)) {
menu.add(Menu.NONE, R.string.context_menu_appops, Menu.NONE,
activity.getString(R.string.context_menu_appops));
}
int size = menu.size();
for (int i = 0; i < size; ++i) {
menu.getItem(i).setOnMenuItemClickListener(this);
}
String important = activity.getLabel("", packageName);
if (!TextUtils.isEmpty(important)) {
menu.add(AppsLabelLoader.trim(important));
}
}
示例10: startAnkiDroid
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public boolean startAnkiDroid() {
PackageManager manager = mContext.getPackageManager();
Intent i = manager.getLaunchIntentForPackage(Constant.ANKI_PACKAGE_NAME);
if (i == null) {
return false;
}
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addCategory(Intent.CATEGORY_LAUNCHER);
mContext.startActivity(i);
return true;
}
示例11: openApp
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* 打开包名packageName的App启动界面
* @param context
* @param packageName
*/
public void openApp(Context context,String packageName) {
PackageManager packageManager = context.getPackageManager();
Intent intent = packageManager.getLaunchIntentForPackage(packageName);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(intent);
}
示例12: onListItemClick
import android.content.pm.PackageManager; //导入方法依赖的package包/类
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
ApkItem item = adapter.getItem(position);
if (v.getId() == R.id.button2) {
PackageManager pm = getActivity().getPackageManager();
Intent intent = pm.getLaunchIntentForPackage(item.packageInfo.packageName);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} else if (v.getId() == R.id.button3) {
doUninstall(item);
}
}
示例13: loadLabel
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public String loadLabel(PackageManager packageManager, PackageInfo packageInfo) {
long lastUpdateTime = packageInfo.lastUpdateTime;
if (lastUpdateTime > mLastUpdateTime) {
mLastUpdateTime = lastUpdateTime;
}
String packageName = packageInfo.packageName;
if (lastUpdateTime <= mLastSync && mPreferences.contains(packageName)) {
return mPreferences.getString(packageName, packageName);
} else {
Intent launchIntent = packageManager.getLaunchIntentForPackage(packageName);
CharSequence label;
if (launchIntent == null) {
label = packageInfo.applicationInfo.loadLabel(packageManager);
} else {
label = packageManager.resolveActivity(launchIntent, 0).activityInfo
.loadLabel(packageManager);
}
if (label == null) {
label = packageName;
}
String name = trim(label).toString();
if (!label.equals(mPreferences.getString(packageName, null))) {
mPreferences.edit().putString(packageName, name).apply();
}
return name;
}
}
示例14: c
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private void c() {
PackageManager packageManager = getPackageManager();
String packageName = getApplicationContext().getPackageName();
if (packageName.isEmpty()) {
z.d(z[1], z[2]);
return;
}
Intent launchIntentForPackage = packageManager.getLaunchIntentForPackage(packageName);
if (launchIntentForPackage == null) {
z.d(z[1], z[0]);
return;
}
launchIntentForPackage.addFlags(335544320);
startActivity(launchIntentForPackage);
}
示例15: accept
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public boolean accept(PackageManager pm, PackageInfo packageInfo, boolean showAllApps) {
BreventActivity activity = getActivity();
ApplicationInfo appInfo = packageInfo.applicationInfo;
String packageName = packageInfo.packageName;
// hard limit
if (appInfo.uid < Process.FIRST_APPLICATION_UID) {
return false;
}
// filter for fragment
if (!mFragment.accept(pm, packageInfo)) {
return false;
}
if (activity != null) {
if (activity.isLauncher(packageName)) {
// always show launcher
return true;
}
if (activity.isGms(packageName)) {
// always show gms
return true;
}
if (activity.isBrevent(packageName)) {
// always for brevented apps
return true;
}
}
if (showAllApps || mFragment.supportAllApps()) {
// always for all apps
return true;
}
return pm.getLaunchIntentForPackage(packageName) != null;
}