如何在使用ACTION_SEND意图时过滤掉特定应用?这个问题已经以各种方式提出,但我还没有能够根据给出的答案收集解决方案。希望有人可以提供帮助。我想提供在应用程序内共享的功能。 喜欢这张照片! http://i.imgur.com/6yeUfgV.png
答案 0 :(得分:0)
由于您无法控制可用的应用程序,您需要自己对该对话框进行硬编码,然后根据用户的选择,专门启动ACTION_SEND意图。
本网站的解释:http://clickclickclack.wordpress.com/2012/01/03/intercepting-androids-action_send-intents/
创建一个活动“ShareActivity”,显示带有ListView的布局。 然后按以下方式实现适配器:
public class ShareIntentListAdapter extends ArrayAdapter
{
Activity context;
Object[] items;
boolean[] arrows;
int layoutId;
public ShareIntentListAdapter(Activity context, int layoutId, Object[] items) {
super(context, layoutId, items);
this.context = context;
this.items = items;
this.layoutId = layoutId;
}
public View getView(int pos, View convertView, ViewGroup parent) {
LayoutInflater inflater=context.getLayoutInflater();
View row = inflater.inflate(layoutId, null);
TextView label = (TextView) row.findViewById(R.id.text1);
label.setText(((ResolveInfo)items[pos]).activityInfo.applicationInfo.loadLabel(context.getPackageManager()).toString());
ImageView image = (ImageView) row.findViewById(R.id.logo);
image.setImageDrawable(((ResolveInfo)items[pos]).activityInfo.applicationInfo.loadIcon(context.getPackageManager()));
return(row);
}
}
然后在你的“ShareActivity”中,给listView充气,创建一个数组,其中包含你想要为你想要的每个意图显示的内容(例如logo / name / FB,FB Messenger,Twitter等等),以及然后使用此数组创建ShareIntentListAdapter并将其附加到listView。
最后一步是处理onClick方法,点击项目并启动所选的意图。
答案 1 :(得分:0)
作为@NSimon回答我是通过自己硬编辑这个对话框得到的,然后根据用户的选择,专门启动ACTION_SEND意图
public void ShareDialog_popualate() {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle(getResources().getString(R.string.sharingBy));
ListView list = new ListView(MainActivity.this);
list.setBackgroundColor(getResources().getColor(R.color.white));
list.setAdapter(new SharingListAdapter(MainActivity.this));
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
// TODO Auto-generated method stub
if (sharedialog.isShowing()) {
sharedialog.dismiss();
}
IntentShareApp(position);
// Toast.makeText(MainActivity.this,
// "Clicked at Position" + position, Toast.LENGTH_SHORT)
// .show();
}
});
builder.setView(list);
sharedialog = builder.create();
sharedialog.show();
}
和listadapter的cumstome类是
package com.artgine.daleel;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;
public class SharingListAdapter extends BaseAdapter implements ListAdapter {
private Context mContext;
private LayoutInflater inflator;
String[]sharing_names={"Facebook","Whatsapp","Messenger"};
final int[] images = { R.drawable.share_icon,
R.drawable.ic_launcher, R.drawable.send_msg_icon_cancel,
};
public SharingListAdapter(Context context) {
// TODO Auto-generated constructor stub
this.mContext=context;
this.inflator= (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return images.length;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public View getView(int position, View convertView, ViewGroup arg2) {
// TODO Auto-generated method stub
MainListHolder mHolder;
View v = convertView;
if (convertView == null)
{
mHolder = new MainListHolder();
v = inflator.inflate(R.layout.share_items, null);
mHolder.image= (ImageView) v.findViewById(R.id.imgviewshareicon);
mHolder.text=(TextView)v.findViewById(R.id.sharenamebtn);
v.setTag(mHolder);
} else {
mHolder = (MainListHolder) v.getTag();
}
mHolder.image.setImageResource(images[position]);
mHolder.image.setPadding(20, 20, 20, 20);
mHolder.text.setText(sharing_names[position]);
return v;
}
class MainListHolder
{
private ImageView image;
private TextView text;
}
}
以及作为用户选择的内容actionsend
public void IntentShareApp(int position) {
String palystoreApplink = "http://play.google.com/store/apps/details?id="
+ this.getPackageName();
Intent intent = new Intent(
android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
// Add data to the intent, the receiving app will
// decide
// what to do with it.
intent.putExtra(Intent.EXTRA_TEXT,palystoreApplink);
intent.putExtra(Intent.EXTRA_SUBJECT,getResources().getString(R.string.app_name));
startActivity(Intent.createChooser(intent,getResources().getString(R.string.sharingBy)));
}