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

The following examples show how to use android.content.pm.PackageManager#getLaunchIntentForPackage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Tools.java    From Hangar with GNU General Public License v3.0 8 votes vote down vote up
protected static boolean isBlacklistedOrBad(String packageName, Context context, TasksDataSource db) {
    try {
        PackageManager pkgm = context.getPackageManager();
        Intent intent = pkgm.getLaunchIntentForPackage(packageName);
        if (intent == null)
            throw new PackageManager.NameNotFoundException();

    } catch (PackageManager.NameNotFoundException e) {
        return true;
    }
    for (String blTask : getBlacklisted(db)) {
        if (packageName.equals(blTask)) {
            return true;
        }
    }
    return false;
}
 
Example 2
Source File: LoginActivity.java    From MyOwnNotes with GNU General Public License v3.0 6 votes vote down vote up
private void openCloudApp(String packageName) {
    PackageManager manager = getPackageManager();
    try {
        Intent i = manager.getLaunchIntentForPackage(packageName);
        if (i == null) {
            throw new PackageManager.NameNotFoundException();
        }
        i.addCategory(Intent.CATEGORY_LAUNCHER);
        startActivity(i);
    } catch (PackageManager.NameNotFoundException e) {
        try {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName)));
        } catch (android.content.ActivityNotFoundException anfe) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName)));
        }
    }
}
 
Example 3
Source File: InstalledFragment.java    From DroidPlugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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);
        if (intent != null) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            Log.i("DroidPlugin", "start " + item.packageInfo.packageName + "@" + intent);
            startActivity(intent);
        } else {
            Log.e("DroidPlugin", "pm " + pm.toString() + " no find intent " + item.packageInfo.packageName);
        }
    } else if (v.getId() == R.id.button3) {
        doUninstall(item);
    }
}
 
Example 4
Source File: AppUtil.java    From PinyinSearchLibrary with Apache License 2.0 6 votes vote down vote up
/**
 * Return true when start app success,otherwise return false.
 * @param context
 * @param packageName
 * @return
 */
public static boolean startApp(Context context,String packageName){
	boolean startAppSuccess=false;
	do{
		if((null==context)||TextUtils.isEmpty(packageName)){
			break;
		}
		
		PackageManager pm=context.getPackageManager();
		Intent intent=pm.getLaunchIntentForPackage(packageName);
		
		if(null!=intent){
			context.startActivity(intent);
			startAppSuccess=true;
		}
	}while(false);
	
	
	return startAppSuccess;
}
 
Example 5
Source File: ApplyFragment.java    From MBEStyle with GNU General Public License v3.0 6 votes vote down vote up
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 6
Source File: PushActivity.java    From letv with Apache License 2.0 5 votes vote down vote up
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 7
Source File: DonateActivity.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
private void openZfb() {
    try {
        PackageManager packageManager = this.getApplicationContext().getPackageManager();
        Intent intent = packageManager.getLaunchIntentForPackage("com.eg.android.AlipayGphone");
        startActivity(intent);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        ACache.get(this).put("getZfbHb", "True", 3 * ACache.TIME_DAY);
        RxBus.get().post(RxBusTag.GET_ZFB_Hb, true);
    }
}
 
Example 8
Source File: NotificationModule.java    From things-notification with Apache License 2.0 5 votes vote down vote up
private String getDefaultSmsPackage() {
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        return Telephony.Sms.getDefaultSmsPackage(reactContext);
    } else {
        String defApp = Settings.Secure.getString(reactContext.getContentResolver(), "sms_default_application");
        PackageManager pm = reactContext.getApplicationContext().getPackageManager();
        Intent iIntent = pm.getLaunchIntentForPackage(defApp);
        ResolveInfo mInfo = pm.resolveActivity(iIntent,0);
        return mInfo.activityInfo.packageName;
    }
}
 
Example 9
Source File: a.java    From letv with Apache License 2.0 5 votes vote down vote up
private static Intent l(Context context, String str) {
    try {
        PackageManager packageManager = context.getPackageManager();
        if (packageManager.getPackageInfo(str, 256) != null) {
            return packageManager.getLaunchIntentForPackage(str);
        }
    } catch (NameNotFoundException e) {
    }
    return null;
}
 
Example 10
Source File: SystemUtil.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
/**
 * 是否是系统main activity
 *
 * @return boolean
 */
public static boolean isMainLaunchActivity(Activity activity) {
    PackageManager packageManager = activity.getApplication().getPackageManager();
    Intent intent = packageManager.getLaunchIntentForPackage(activity.getPackageName());
    if (intent == null) {
        return false;
    }
    ComponentName launchComponentName = intent.getComponent();
    ComponentName componentName = activity.getComponentName();
    if (launchComponentName != null && componentName.toString().equals(launchComponentName.toString())) {
        return true;
    }
    return false;
}
 
Example 11
Source File: MyUtils.java    From Huochexing12306 with Apache License 2.0 5 votes vote down vote up
public static void startApp(Context context, String strPackageName, CharSequence csTipMsg) {
	PackageManager pm = context.getPackageManager();
	Intent intent = pm.getLaunchIntentForPackage(strPackageName);
	if (intent != null){
		context.startActivity(intent);
	}else if (!TextUtils.isEmpty(csTipMsg)){
		Toast.makeText(context, csTipMsg, Toast.LENGTH_SHORT).show();
	}
}
 
Example 12
Source File: NotificationReturnSlot.java    From flutter_media_notification with MIT License 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    switch (intent.getAction()) {
        case "prev":
            FlutterMediaNotificationPlugin.callEvent("prev");
            break;
        case "next":
            FlutterMediaNotificationPlugin.callEvent("next");
            break;
        case "toggle":
            String title = intent.getStringExtra("title");
            String author = intent.getStringExtra("author");
            boolean play = intent.getBooleanExtra("play",true);

            if(play)
                FlutterMediaNotificationPlugin.callEvent("play");
            else
                FlutterMediaNotificationPlugin.callEvent("pause");

            FlutterMediaNotificationPlugin.showNotification(title, author,play);
            break;
        case "select":
            Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
            context.sendBroadcast(closeDialog);
            String packageName = context.getPackageName();
            PackageManager pm = context.getPackageManager();
            Intent launchIntent = pm.getLaunchIntentForPackage(packageName);
            context.startActivity(launchIntent);

            FlutterMediaNotificationPlugin.callEvent("select");
    }
}
 
Example 13
Source File: SelectAppFragment.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
/**
 * @return a list of apps that users are allowed to select from.
 */
protected List<String> createAppList() {
    List<String> appList = new ArrayList<>();
    PackageManager pm = getActivity().getPackageManager();
    List<ApplicationInfo> allApps = pm.getInstalledApplications(0 /* No flag */);
    Collections.sort(allApps, new ApplicationInfo.DisplayNameComparator(pm));
    for(ApplicationInfo info : allApps) {
        if ((pm.getLaunchIntentForPackage(info.packageName)) != null) {
            appList.add(info.packageName);
        }
    }
    return appList;
}
 
Example 14
Source File: AndroidUtils.java    From Aria with Apache License 2.0 4 votes vote down vote up
/**
 * 启动另外一个App
 */
public static void startOtherApp(Context context, String packageName) {
  PackageManager pm = context.getPackageManager();
  Intent launcherIntent = pm.getLaunchIntentForPackage(packageName);
  context.startActivity(launcherIntent);
}
 
Example 15
Source File: Intent.java    From unity-ads-android with Apache License 2.0 4 votes vote down vote up
private static android.content.Intent intentFromMetadata(JSONObject json) throws IntentException {
	android.content.Intent intent;

	String className = (String)json.opt("className");
	String packageName = (String)json.opt("packageName");
	String action = (String)json.opt("action");
	String uri = (String)json.opt("uri");
	String mimeType = (String)json.opt("mimeType");
	JSONArray categories = (JSONArray)json.opt("categories");
	Integer flags = (Integer)json.opt("flags");
	JSONArray extras = (JSONArray)json.opt("extras");

	if (packageName != null && className == null && action == null && mimeType == null) {
		PackageManager pm = ClientProperties.getApplicationContext().getPackageManager();
		intent = pm.getLaunchIntentForPackage(packageName);

		if (intent != null && flags > -1) {
			intent.addFlags(flags);
		}
	}
	else {
		intent = new android.content.Intent();

		if (className != null && packageName != null)
			intent.setClassName(packageName, className);

		if (action != null)
			intent.setAction(action);

		if (uri != null)
			intent.setData(Uri.parse(uri));

		if (mimeType != null)
			intent.setType(mimeType);

		if (flags != null && flags > -1)
			intent.setFlags(flags);

		if (!setCategories(intent, categories))
		    throw new IntentException(IntentError.COULDNT_PARSE_CATEGORIES, categories);

		if (!setExtras(intent, extras))
			throw new IntentException(IntentError.COULDNT_PARSE_EXTRAS, extras);
	}
	return intent;
}
 
Example 16
Source File: AllTasksListFragment.java    From ActivityLauncher with ISC License 4 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
    ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();
    ExpandableListView list = getView().findViewById(R.id.expandableListView1);

    switch (ExpandableListView.getPackedPositionType(info.packedPosition)) {
        case ExpandableListView.PACKED_POSITION_TYPE_CHILD:
            MyActivityInfo activity = (MyActivityInfo) list.getExpandableListAdapter().getChild(ExpandableListView.getPackedPositionGroup(info.packedPosition), ExpandableListView.getPackedPositionChild(info.packedPosition));
            switch (item.getItemId()) {
                case 0:
                    LauncherIconCreator.createLauncherIcon(getActivity(), activity);
                    break;
                case 1:
                    LauncherIconCreator.launchActivity(getActivity(), activity.component_name);
                    break;
                case 2:
                    DialogFragment dialog = new ShortcutEditDialogFragment();
                    Bundle args = new Bundle();
                    args.putParcelable("activity", activity.component_name);
                    dialog.setArguments(args);
                    dialog.show(getFragmentManager(), "ShortcutEditor");
                    break;
            }
            break;

        case ExpandableListView.PACKED_POSITION_TYPE_GROUP:
            MyPackageInfo pack = (MyPackageInfo) list.getExpandableListAdapter().getGroup(ExpandableListView.getPackedPositionGroup(info.packedPosition));
            switch (item.getItemId()) {
                case 0:
                    boolean success = LauncherIconCreator.createLauncherIcon(getActivity(), pack);
                    Toast.makeText(getActivity(), getString(R.string.error_no_default_activity), Toast.LENGTH_LONG).show();
                    break;
                case 1:
                    PackageManager pm = getActivity().getPackageManager();
                    Intent intent = pm.getLaunchIntentForPackage(pack.package_name);
                    if (intent != null) {
                        Toast.makeText(getActivity(), String.format(getText(R.string.starting_application).toString(), pack.name), Toast.LENGTH_LONG).show();
                        getActivity().startActivity(intent);
                    } else {
                        Toast.makeText(getActivity(), getString(R.string.error_no_default_activity), Toast.LENGTH_LONG).show();
                    }
                    break;
            }
    }
    return super.onContextItemSelected(item);
}
 
Example 17
Source File: AppUtils.java    From RelaxFinger with GNU General Public License v2.0 4 votes vote down vote up
public static boolean startApplication(String packageName) throws ActivityNotFoundException{

        PackageManager pm = context.getPackageManager();
        Intent intent = pm.getLaunchIntentForPackage(packageName);

        if (intent != null) {

            String className = intent.getComponent().getClassName();

            //解决直接用pm.getLaunchIntentForPackage(packageName)会重新打开APP的问题
            Intent intent1 = new Intent(Intent.ACTION_MAIN);
            intent1.addCategory(Intent.CATEGORY_LAUNCHER);
            intent1.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK);
            intent1.setComponent(new ComponentName(packageName, className));

            context.startActivity(intent1);

            return true;

        }else {

            throw new  ActivityNotFoundException();
        }

    }
 
Example 18
Source File: NotificationReceiver.java    From UniLocalNotification with MIT License 4 votes vote down vote up
/**
 * 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);

    NotificationManager manager = (NotificationManager) context.getSystemService(Service.NOTIFICATION_SERVICE);

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
    {
        String channelId = "default";
        NotificationChannel channel = new NotificationChannel(channelId, "Default", NotificationManager.IMPORTANCE_DEFAULT);

        channel.setDescription("Default Notification");
        channel.enableVibration(true);
        channel.canShowBadge();
        channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
        channel.setShowBadge(true);

        manager.createNotificationChannel(channel);

        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);

        Notification notification = new Notification.Builder(context, channelId)
                .setContentTitle(title)
                .setContentText(message)
                .setAutoCancel(true)
                .setContentIntent(pendingIntent)
                .setSmallIcon(context.getResources().getIdentifier("notification_icon", "drawable", context.getPackageName()))
                .setLargeIcon(largeIcon)
                .build();

        manager.notify(requestCode, notification);
    } else {
        // 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
        manager.notify(requestCode, builder.build());
    }
}
 
Example 19
Source File: IntentUtils.java    From Android-utils with Apache License 2.0 2 votes vote down vote up
/**
 * 返回一个用来启动某个应用的意图
 *
 * @param pkgName   应用的包名
 * @param isNewTask 是否作为 NEW TASK 启动指定的应用
 * @return 意图
 */
public static Intent getLaunchAppIntent(final String pkgName, final boolean isNewTask) {
    PackageManager pm = UtilsApp.getApp().getPackageManager();
    Intent intent = pm.getLaunchIntentForPackage(pkgName);
    return getIntent(intent, isNewTask);
}
 
Example 20
Source File: AppUtils.java    From Cangol-appcore with Apache License 2.0 2 votes vote down vote up
/**
 * 启动应用
 *
 * @param context
 * @param packageName
 */
public static void launch(Context context, String packageName) {
    final PackageManager packageManager = context.getPackageManager();
    final Intent intent = packageManager.getLaunchIntentForPackage(packageName);
    context.startActivity(intent);
}