Java Code Examples for android.content.pm.PackageManager.getLaunchIntentForPackage()

The following are Jave code examples for showing how to use getLaunchIntentForPackage() of the android.content.pm.PackageManager class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: MBEStyle   File: ApplyFragment.java   View Source Code Vote up 7 votes
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();
    }
}
 
Example 2
Project: PasswordSafe-AndroidClient   File: NavigationController.java   View Source Code Vote up 6 votes
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;
    }
}
 
Example 3
Project: mobile-store   File: AppUpdateStatusManager.java   View Source Code Vote up 6 votes
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;
}
 
Example 4
Project: StartThirdApp   File: ActivityStartUtil.java   View Source Code Vote up 6 votes
/**
 * 启动制定包名的其他应用
 * 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;
}
 
Example 5
Project: Detoxiom   File: AppNameAndLogoProvider.java   View Source Code Vote up 6 votes
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;
}
 
Example 6
Project: Detoxiom   File: AppNameAndLogoProvider.java   View Source Code Vote up 6 votes
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;
}
 
Example 7
Project: Brevent   File: AppsIconTask.java   View Source Code Vote up 6 votes
@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;
}
 
Example 8
Project: prevent   File: PackageUtils.java   View Source Code Vote up 6 votes
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);
    }
}
 
Example 9
Project: Brevent   File: AppsItemViewHolder.java   View Source Code Vote up 5 votes
@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));
    }
}
 
Example 10
Project: quiz_helper   File: AnkiDroidHelper.java   View Source Code Vote up 5 votes
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;
}
 
Example 11
Project: TPlayer   File: AceHelper.java   View Source Code Vote up 5 votes
/**
 * 打开包名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);
}
 
Example 12
Project: DroidPlugin   File: InstalledFragment.java   View Source Code Vote up 5 votes
@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);
    }
}
 
Example 13
Project: Brevent   File: AppsLabelLoader.java   View Source Code Vote up 5 votes
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;
    }
}
 
Example 14
Project: letv   File: PushActivity.java   View Source Code Vote up 5 votes
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);
}
 
Example 15
Project: Brevent   File: AppsItemAdapter.java   View Source Code Vote up 5 votes
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;
}
 
Example 16
Project: Leanplum-Android-SDK   File: LeanplumPushService.java   View Source Code Vote up 5 votes
private static Intent getActionIntent(Context context) {
  Class<? extends Activity> callbackClass = LeanplumPushService.getCallbackClass();
  if (callbackClass != null) {
    return new Intent(context, callbackClass);
  } else {
    PackageManager pm = context.getPackageManager();
    return pm.getLaunchIntentForPackage(context.getPackageName());
  }
}
 
Example 17
Project: FlickLauncher   File: IconPackManager.java   View Source Code Vote up 5 votes
public Drawable getDrawableIconForPackage(String appPackageName, Drawable defaultDrawable) {
    if (!mLoaded)
        load();

    PackageManager pm = mContext.getPackageManager();
    Intent launchIntent = pm.getLaunchIntentForPackage(appPackageName);
    String componentName = null;
    if (launchIntent != null)
        componentName = pm.getLaunchIntentForPackage(appPackageName).getComponent().toString();
    String drawable = mPackagesDrawables.get(componentName);
    if (drawable != null)
    {
        return loadDrawable(drawable);
    }
    else
    {
        // try to get a resource with the component filename
        if (componentName != null)
        {
            int start = componentName.indexOf("{")+1;
            int end = componentName.indexOf("}",  start);
            if (end > start)
            {
                drawable = componentName.substring(start,end).toLowerCase(Locale.getDefault()).replace(".","_").replace("/", "_");
                if (iconPackres.getIdentifier(drawable, "drawable", packageName) > 0)
                    return loadDrawable(drawable);
            }
        }
    }
    return defaultDrawable;
}
 
Example 18
Project: Android_AutoSignInTool   File: MainPage.java   View Source Code Vote up 4 votes
private void autoLaunch(String name) {
    PackageManager packageManager = this.getPackageManager();
    Intent mBootUpIntent = packageManager.getLaunchIntentForPackage(name);
    mBootUpIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    this.startActivity(mBootUpIntent);
}
 
Example 19
Project: UniLocalNotification   File: NotificationReceiver.java   View Source Code Vote up 4 votes
/**
 * Receiving notification event
 * @param context current context
 * @param intent received intent
 */
@Override
public void onReceive(Context context, Intent intent) {

    // get notification info
    String message = intent.getStringExtra("MESSAGE");
    String title = intent.getStringExtra("TITLE");
    int requestCode = intent.getIntExtra("REQUEST_CODE", 0);

    // create intent for taping notification
    final PackageManager pm=context.getPackageManager();
    Intent intentCustom = pm.getLaunchIntentForPackage(context.getPackageName());

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intentCustom,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // create icon bitmap
    ApplicationInfo applicationInfo = null;
    try {
        applicationInfo = pm.getApplicationInfo(context.getPackageName(),PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return;
    }
    final int appIconResId=applicationInfo.icon;
    Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), appIconResId);

    // create notification builder
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setContentIntent(contentIntent);

    // set notification info
    builder.setTicker("");
    builder.setContentTitle(title);
    builder.setContentText(message);

    // set icon
    builder.setLargeIcon(largeIcon);
    builder.setSmallIcon(context.getResources().getIdentifier("notification_icon", "drawable", context.getPackageName()));

    // fire now
    builder.setWhen(System.currentTimeMillis());

    // set device notification settings
    builder.setDefaults(Notification.DEFAULT_SOUND
            | Notification.DEFAULT_VIBRATE
            | Notification.DEFAULT_LIGHTS);

    // tap to cancel
    builder.setAutoCancel(true);

    // fire notification
    NotificationManager manager = (NotificationManager) context.getSystemService(Service.NOTIFICATION_SERVICE);
    manager.notify(requestCode, builder.build());
}
 
Example 20
Project: FreeStreams-TVLauncher   File: AllApp.java   View Source Code Vote up 4 votes
@SuppressLint("NewApi")
@Override
public void onClick(View arg0) {
	int id = arg0.getId();
	int position = -1;
	switch(id)
	{
	case R.id.app_item0:
		position = mPagerIndex*15 + 0;
		break;
	case R.id.app_item1:
		position = mPagerIndex*15 + 1;
		break;
	case R.id.app_item2:
		position = mPagerIndex*15 + 2;
		break;
	case R.id.app_item3:
		position = mPagerIndex*15 + 3;
		break;
	case R.id.app_item4:
		position = mPagerIndex*15 + 4;
		break;
	case R.id.app_item5:
		position = mPagerIndex*15 + 5;
		break;
	case R.id.app_item6:
		position = mPagerIndex*15 + 6;
		break;
	case R.id.app_item7:
		position = mPagerIndex*15 + 7;
		break;
	case R.id.app_item8:
		position = mPagerIndex*15 + 8;
		break;
	case R.id.app_item9:
		position = mPagerIndex*15 + 9;
		break;
	case R.id.app_item10:
		position = mPagerIndex*15 + 10;
		break;
	case R.id.app_item11:
		position = mPagerIndex*15 + 11;
		break;
	case R.id.app_item12:
		position = mPagerIndex*15 + 12;
		break;
	case R.id.app_item13:
		position = mPagerIndex*15 + 13;
		break;
	case R.id.app_item14:
		position = mPagerIndex*15 + 14;
		break;
		default:
			break;
	}
     if(position != -1)
	{
		PackageManager manager = mContext.getPackageManager();
		String packageName = mAppList.get(position).getPackageName();
		Intent intent=new Intent(); 
	    intent =manager.getLaunchIntentForPackage(packageName);
	    mContext.startActivity(intent);
	}
}