Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hai frnds,

my application need to open Google play store and display a particular apps.

for that i use the following code

C#
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+appname[turn-3])));


here appname string contain the application name..

it opens the Google play store. but it display a message "item not contained"


pls help mee
Posted

You'll want to use the specified market protocol:

C#
final String appName = "com.example";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+appName)));



Keep in mind, this will crash on any device that does not have the Market installed (the emulator, for example). Hence, I would suggest something like:

C#
try {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+appName)));
} catch (android.content.ActivityNotFoundException anfe) {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id="+appName)));
}



You can find more on Market Intents here: http://developer.android.com/guide/publishing/publishing.html#marketintent[^].
 
Share this answer
 
Comments
ranju007 9-Oct-12 1:17am    
yaa i use the same code.. i just copy the startActivity method...


instead of appname i need to use the package name of that application.. from where i got the package name
Jaydeep Jadav 9-Oct-12 2:17am    
Tell me how you are getting the application name in your application.
This helper function retrieves all installed apps with the application name, package name, version-number and -code as well as the icons. The method getPackages() returns an ArrayList with all the apps.

Java
class PInfo {
    private String appname = "";
    private String pname = "";
    private String versionName = "";
    private int versionCode = 0;
    private Drawable icon;
    private void prettyPrint() {
        Log.v(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode);
    }
}

private ArrayList<PInfo> getPackages() {
    ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */
    final int max = apps.size();
    for (int i=0; i<max; i++) {
        apps.get(i).prettyPrint();
    }
    return apps;
}

private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
    ArrayList<PInfo> res = new ArrayList<PInfo>();
    List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
    for(int i=0;i<packs.size();i++) {
        PackageInfo p = packs.get(i);
        if ((!getSysPackages) && (p.versionName == null)) {
            continue ;
        }
        PInfo newInfo = new PInfo();
        newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
        newInfo.pname = p.packageName;
        newInfo.versionName = p.versionName;
        newInfo.versionCode = p.versionCode;
        newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
        res.add(newInfo);
    }
    return res;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900