首页 > 解决方案 > Android widget listview items onclick startActivity 调用外部应用

问题描述

我必须确保通过单击小部件列表中的项目,对外部应用程序产生了意图。

意图:

Intent appIntent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://instagram.com/_u/"+str));
appIntent.setPackage("com.instagram.android");
Intent webIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://instagram.com/"+str));
 try {
     startActivity(appIntent);
} catch (ActivityNotFoundException ex) {
    startActivity(webIntent);
}

我试图把它放在 getViewAt 中,但它不起作用。  

Intent intent;
try {
  intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://status?status_id=" + listItem.id));
  intent.setPackage("com.twitter.android");
} catch (ActivityNotFoundException ex) {
  intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/" + listItem.username + "/status/" + listItem.id));
}
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
remoteView.setOnClickFillInIntent(R.id.widgetItemContainer, intent);

标签: javaandroidlistviewandroid-widgetonclicklistener

解决方案


推荐阅读