【发布时间】:2012-03-21 08:24:30
【问题描述】:
如果应用程序已经安装在android中如何发出警报,如果没有如何提供到android market的链接???
我在这里试过
在 For 循环中我需要退出
public void onClick(View v)
{
final PackageManager pm = getPackageManager();
//here i get set of installed apps
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages)
{
//how do i check for installed package with clicked package
String data=packageInfo.packageName;
if(data.equals("com.bb"))
{
String TAG ="MyActivity";
Log.d(TAG, "Installed package :" + packageInfo.packageName);
Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName));
Toast.makeText(Listing.this, "You have Installed this Package:com.bb" , Toast.LENGTH_SHORT).show();
}
//if the package is not installed, do this
else
{
String dictionary=items[position];
Toast.makeText(Listing.this, dictionary , Toast.LENGTH_SHORT).show();
if(dictionary.equalsIgnoreCase("Acronyms"))
{
String dictionary2="MAcronyms";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=com." + dictionary2));
startActivity(intent);
}
}
}
}
问题是如果条件失败,则循环仍在运行(例如,它进入 else 块的 55 次)
【问题讨论】:
标签: android android-layout android-intent android-emulator android-widget