从我的应用程序打开Google Play商店 [英] open google play store from my Application
问题描述
hai frnds,
我的应用程序需要打开Google Play商店并显示特定的应用程序.
为此,我使用以下代码
hai frnds,
my application need to open Google play store and display a particular apps.
for that i use the following code
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+appname[turn-3])));
这里的appname字符串包含应用程序名称..
它会打开Google Play商店.但它显示一条消息项目不包含"
请帮助我
here appname string contain the application name..
it opens the Google play store. but it display a message "item not contained"
pls help mee
推荐答案
您将要使用指定的市场协议:
You''ll want to use the specified market protocol:
final String appName = "com.example";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+appName)));
请记住,这将在未安装Market的任何设备(例如模拟器)上崩溃.因此,我建议如下:
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:
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)));
}
您可以在此处找到有关市场意图"的更多信息: http://developer.android.com/guide/publishing/publishing .html#marketintent [^ ].
You can find more on Market Intents here: http://developer.android.com/guide/publishing/publishing.html#marketintent[^].
此帮助器函数将检索所有已安装的应用程序,包括应用程序名称,程序包名称,版本号和-code以及图标.方法getPackages()返回带有所有应用程序的ArrayList.
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.
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;
}
这篇关于从我的应用程序打开Google Play商店的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!