检查第三方应用程序,如果未安装则打开
我正在开发一个类,当用户选择该类时应该打开一个应用程序。如果该应用程序未安装,他们将单击“查找它”按钮并安装它。
这是我到目前为止所拥有的内容
public class calc extends Activity {
static final String MARKET_SEARCH_Q_PNAME_PROVIDER = "market://search?q=pname:com.packagename.package";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.getpft);
setTitle("Install Marine PFT?");
((Button) findViewById(R.id.Ok)).setOnClickListener(new Openpft());
((Button) findViewById(R.id.FindIt)).setOnClickListener(new FindZxingOnclickListener());
}
public class FindZxingOnclickListener implements OnClickListener {
public void onClick(View v) {
Intent marketLaunch = new Intent(Intent.ACTION_VIEW);
marketLaunch.setData(Uri.parse(MARKET_SEARCH_Q_PNAME_PROVIDER));
startActivity(marketLaunch);
}}
};
到目前为止,页面打开并且它正确搜索该应用程序。但是,现在应用程序已下载,我需要自动跳过此屏幕并仅打开该应用程序。这是怎么做到的?
I am working on a class that when selected by the user should open an application. If that application is not installed they will click the "Find it" button and install it.
Here is what I have so far
public class calc extends Activity {
static final String MARKET_SEARCH_Q_PNAME_PROVIDER = "market://search?q=pname:com.packagename.package";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.getpft);
setTitle("Install Marine PFT?");
((Button) findViewById(R.id.Ok)).setOnClickListener(new Openpft());
((Button) findViewById(R.id.FindIt)).setOnClickListener(new FindZxingOnclickListener());
}
public class FindZxingOnclickListener implements OnClickListener {
public void onClick(View v) {
Intent marketLaunch = new Intent(Intent.ACTION_VIEW);
marketLaunch.setData(Uri.parse(MARKET_SEARCH_Q_PNAME_PROVIDER));
startActivity(marketLaunch);
}}
};
So far the page opens up and it searches correctly for the app. However now that the app is downloaded I need to automatically skip this screen and just open that app. How is that done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不知何故,您正在启动该应用程序。据推测,您有一个
Intent
传递给startActivity()
来执行此操作。如果是这样,您有两个选择:只需调用
startActivity()
并路由到ActivityNotFoundException
catch
块中的上述代码 p>使用
PackageManager
和queryIntentActivities()
查看是否有任何内容会响应您的Intent
,如果没有,则路由到您的上述代码,而不先调用startActivity()
< /p>Somehow, you are launching that app. Presumably, you have an
Intent
that you are passing tostartActivity()
that does this. If so, you have two choices:Just call
startActivity()
and route to your above code in theActivityNotFoundException
catch
blockUse
PackageManager
andqueryIntentActivities()
to see if anything will respond to yourIntent
, and if not, route to your above code without callingstartActivity()
first