简体   繁体   中英

how to start another application from my application in android

final List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);

The above PackageInfo class for get the list of packages then

get package names for :

    ViewHendler hendler = new ViewHendler();
                hendler.textLable = (TextView)convertView.findViewById(R.id.textView);
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(packageName);



startActivity( LaunchIntent );

then start applicathin using package name call :launchApp(packageName)

void launchApp(String packageName) {

        Intent mIntent = getPackageManager().getLaunchIntentForPackage(packageName);
       if (mIntent != null) {
            try {
                startActivity(mIntent);
            } catch (ActivityNotFoundException err) {
                Toast t = Toast.makeText(getApplicationContext(),
                        R.string.app_not_found, Toast.LENGTH_SHORT);
                t.show();
            }
        }
    }

But didn't get result(start another application from my application).

It's right way to use:

Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.name");
startActivity(LaunchIntent);

But probably you have no permission, or you don't have application there.
Firstly check your packageName parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM