Android分享一张图片_android 分享一张图片到basequickadapter中-程序员宅基地

技术标签: 图片  Android分享  android  


public class Act_Share extends Activity {

	private ShareCustomAdapter adapter;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.act_share);
		
		ImageView btn_back = (ImageView) findViewById(R.id.share_back);
		btn_back.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});

		ListView shareList = (ListView) findViewById(R.id.act_share_list);
		List<AppInfo> shareAppInfos = getShareAppList();
		adapter = new ShareCustomAdapter(this, shareAppInfos);
		shareList.setAdapter(adapter);
		shareList.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				AppInfo appInfo = (AppInfo) adapter.getItem(position);
				Intent shareIntent = new Intent(Intent.ACTION_SEND);
				shareIntent.setComponent(new ComponentName(appInfo.packageName,
						appInfo.appLauncherClassName));
				shareIntent.setType("image/*");
				File file = new File("/sdcard/com.igoatech.wxrepack/shareimg.png");
				if (!file.exists()) {
					Bitmap bm = FileUtil.drawableToBitmap(getResources()
							.getDrawable(R.drawable.erweima));
					FileUtil.saveBitmap(bm, file);
				}
				Uri imageUri = Uri.fromFile(file);
				shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
				startActivity(shareIntent);
			}
		});
	}
	
	private List<AppInfo> getShareAppList() {
		List<AppInfo> shareAppInfos = new ArrayList<AppInfo>();
		PackageManager packageManager = getPackageManager();
		List<ResolveInfo> resolveInfos = getShareApps(this);
		if (null == resolveInfos) {
			return null;
		} else {
			for (ResolveInfo resolveInfo : resolveInfos) {
				AppInfo appInfo = new AppInfo();
				appInfo.packageName = resolveInfo.activityInfo.packageName;
				appInfo.appLauncherClassName = resolveInfo.activityInfo.name;
				appInfo.appName = resolveInfo.loadLabel(packageManager)
						.toString();
				appInfo.appIcon = resolveInfo.loadIcon(packageManager);
				shareAppInfos.add(appInfo);
			}
		}
		return shareAppInfos;
	}
	public List<ResolveInfo> getShareApps(Context context) {
		List<ResolveInfo> mApps = new ArrayList<ResolveInfo>();
		Intent intent = new Intent(Intent.ACTION_SEND, null);
		intent.addCategory(Intent.CATEGORY_DEFAULT);
		intent.setType("text/plain");
		PackageManager pManager = context.getPackageManager();
		mApps = pManager.queryIntentActivities(intent,
				PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);
		return mApps;
	}
}
XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/all_bg" >

    <LinearLayout
        android:id="@+id/share_title"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@color/main_bg"
        android:gravity="center_vertical" >

        <ImageView
            android:id="@+id/share_back"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:background="@drawable/fanhui" />

        <TextView
            style="@style/all_title"
            android:text="@string/share" />
    </LinearLayout>

    <ListView
        android:id="@+id/act_share_list"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/share_title"
        android:layout_marginTop="4dp"
        android:background="#FFFFFF"
        android:cacheColorHint="#00000000"
        android:divider="@color/line"
        android:dividerHeight="1.0dip"
        android:fadingEdge="none"
        android:footerDividersEnabled="false"
        android:headerDividersEnabled="true" />

</RelativeLayout>



adapter:

public class ShareCustomAdapter extends BaseAdapter {

	private Context context;
	private List<AppInfo> list;

	public ShareCustomAdapter(Context context, List<AppInfo> list) {
		super();
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View v, ViewGroup arg2) {

		if (v == null) {
			v = LayoutInflater.from(context).inflate(
					R.layout.share_item, null);
		}

		AppInfo item = list.get(position);

		ImageView iv = (ImageView) v.findViewById(R.id.share_item_icon);
		TextView tv = (TextView) v.findViewById(R.id.share_item_name);

		iv.setImageDrawable(item.appIcon);
		tv.setText(item.appName);
		v.setTag(item);

		return v;
	}

}
XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:orientation="horizontal">

    <ImageView 
		android:id="@+id/share_item_icon" 
		android:layout_width="45dp" 
		android:layout_height="45dp" 
		android:layout_marginLeft="3.0dip" 
		android:scaleType="fitXY" />
	<TextView 
		android:id="@+id/share_item_name" 
		android:layout_gravity="center_vertical"
		android:layout_width="wrap_content" 
		android:layout_height="wrap_content" 
		android:text="分享" 
		android:singleLine="true" 
		android:textSize="14sp"
		android:textColor="@color/item_text"
		android:layout_marginLeft="5dip" />

</LinearLayout>

public class AppInfo {

	public String appName = "";
	public String packageName = "";
	public String versionName = "";
	public int versionCode = 0;
	public Drawable appIcon = null;
	public String date = "";
	public String size = "";
	public String iconUrl = "";
	public String downloadurl = "";
	public String brief = "";
	public int downloadPercent = 0;
	public boolean isInWhite = false;
	public PackageInfo packageInfo = null;
	public String isInstalled = "false";
	public String path = "";
	public PackageInfo packageinfo = null;
	public String appLauncherClassName = "";
	public int number = 0;
	public String filePath = "";
	public int installedType = 1;
	public int upgrade = 0;
	public boolean isChecked = false;

	public void print() {
		Log.v("app", "Name:" + appName + " Package:" + packageName);
		Log.v("app", "Name:" + appName + " versionName:" + versionName);
		Log.v("app", "Name:" + appName + " versionCode:" + versionCode);
	}

}

图片处理代码:

/**
	 * Drawableת��ΪBitmap
	 */
	public static Bitmap drawableToBitmap(Drawable drawable) {
		int width = drawable.getIntrinsicWidth();
		int height = drawable.getIntrinsicHeight();
		Bitmap bitmap = Bitmap.createBitmap(width, height, drawable
				.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
				: Bitmap.Config.RGB_565);
		Canvas canvas = new Canvas(bitmap);
		drawable.setBounds(0, 0, width, height);
		drawable.draw(canvas);
		return bitmap;

	}

	/** ���淽�� */
	public static void saveBitmap(Bitmap bm, File file) {
		// Log.e(TAG, "����ͼƬ");

		try {

			if (!file.exists()) {
				file.getParentFile().mkdirs();
				file.createNewFile();
			}

			FileOutputStream out = new FileOutputStream(file);
			bm.compress(Bitmap.CompressFormat.PNG, 90, out);
			out.flush();
			out.close();
			// Log.i(TAG, "�Ѿ�����");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}











版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Jianglei0904/article/details/54094642

智能推荐

js对象遍历输出的时候真的是按照顺序输出吗?_map循环遍历对象数据是顺序的吗-程序员宅基地

文章浏览阅读1.3w次。js对象遍历输出的时候真的是按照顺序输出吗?  下边就来实践一下:var obj={'3':'ccc',name:'abc',age:23,school:'sdfds',class:'dfd',hobby:'dsfd'};Object.keys(obj)输出:["3", "name", "age", "school", "class", "hobby"];换一下对象顺序,var obj=_map循环遍历对象数据是顺序的吗

HDU--4305(生成树计数)-程序员宅基地

文章浏览阅读176次。2015-09-0722:23:26【传送门】题意:平面上300个点,如果两点之间距离<=R,且两点形成的线段上没有另外的点,那么两点之间有一条无向边。问生成树的方案数。思路:暴力n^2建图,关于判断两点形成线段上是否有其他点,比如判断 k 点知否在 i ,j 之间,首先看斜率是否相等,不能直接求斜率,而应该转化为乘式;再判断 dis(i,k)+dis(k,j)是否等..._hdu4305

阿里云OSS请求文件跨域问题Access-Control-Allow-Origin_oss预签名url access-control-allow-origin-程序员宅基地

文章浏览阅读2.2k次。跨域问题网上很多解决方案提示到这里配置但是不生效,一定要勾选Vary:Origin这个选项,请求的时候浏览器记得请求在控制台要清理缓存。_oss预签名url access-control-allow-origin

OpenCV - C++ - cv::setWindowProperty-程序员宅基地

文章浏览阅读4k次,点赞2次,收藏2次。OpenCV - C++ - cv::setWindowPropertyHigh-level GUI#include <opencv2/highgui.hpp>1. setWindowProperty()void cv::setWindowProperty(const String &winname, int prop_id, double prop_value) - C++None = cv.setWindowProperty(winname, prop_id, prop__setwindowproperty

Qt Creator 4.13中的CMake项目配置_qt cmake configuration-程序员宅基地

文章浏览阅读5.1k次,点赞3次,收藏4次。在Qt Creator中配置中型到大型CMake项目可能是一个挑战。这是因为您需要给CMake传递正确配置项目的选项太多了。让我们以Qt Creator的CMake为例。不同于qmake构建,CMake构建可配置你想要构建的插件。_qt cmake configuration

探测网络设备(主机、路由器)存活的方法-程序员宅基地

文章浏览阅读2.1k次。//=======================ping-test============================void ping_test(char *ipaddress){ //add by sun-1014 char command[100]="ping -c 5 "; char ipaddr[20]; strcpy(ipaddr,_探测网络设备

随便推点

读jQuery之二十(Deferred对象)-程序员宅基地

文章浏览阅读55次。为什么80%的码农都做不了架构师?>>> ...

C++代码实现Top-K问题最优解决办法_c++用优先队列解决topk-程序员宅基地

文章浏览阅读1.6k次。Top-K问题Top-K问题1、问题描述2、解法思想和实现Top-K问题1、问题描述Top-K问题是一个十分经典的问题,一般有以下两种方式来描述问题:在10亿的数字里,找出其中最大的100个数;或者在一个包含n个整数的数组中,找出最大的100个数。前边两种问题描述稍有区别,但都是说的Top-K问题,前一种描述方式是说这里也许没有足够的空间存储大量的数字或其他东西,我们最好可以在一边输入数据,一边求出结果,而不需要存储数据;后一种说法则表示可以存储数据,这种情况下,最简单直观的想法就是对数组进行排序,_c++用优先队列解决topk

怎么用matlab剔除数据的异常值(3σ准则)_3sigma原则matlab-程序员宅基地

文章浏览阅读5.2w次,点赞27次,收藏379次。参考:https://blog.csdn.net/weixin_30633405/article/details/951770093σ准则又称为拉依达准则,它是先假设一组检测数据只含有随机误差,对其进行计算处理得到标准偏差,按一定概率确定一个区间,认为凡超过这个区间的误差,就不属于随机误差而是粗大误差,含有该误差的数据应予以剔除。且3σ适用于有较多组数据的时候。这种判别处理原理及方法仅局限于对正态或近似正态分布的样本数据处理,它是以测量次数充分大为前提的,当测量次数较少的情形用准则剔除粗大误_3sigma原则matlab

导入PYQT5不能使用的坑_pdroid3已经导入pyqt5怎么不管用-程序员宅基地

文章浏览阅读5.1k次,点赞4次,收藏17次。如图:import进来之后里面的类全都不能用是因为这个引用路径下面有中文。改成英文的就不报错了,如果还是报错,那就新建一个项目命名成英文_pdroid3已经导入pyqt5怎么不管用

手推线性模型及最小二乘法(房价预测实例)_基于最小二乘法的房价预测实验报告-程序员宅基地

文章浏览阅读1.4k次,点赞4次,收藏24次。手推线性模型及最小二乘法(房价预测实例)线性模型及最小二乘法推导房价预测实例Reference线性模型及最小二乘法推导房价预测实例生成数据#生成数据import numpy as np#生成随机数np.random.seed(1234)x = np.random.rand(500,3)#构建映射关系,模拟真实的数据待预测值,映射关系为y = 4.2 + 5.7*x1 + 1..._基于最小二乘法的房价预测实验报告

多文件使用全局变量时extern的规范用法_extern变量多个文件中修改-程序员宅基地

文章浏览阅读494次。关键字extern用来声明变量或者函数是一个外部变量或者外部函数,也就是说告诉编译器是在其他文件中定义的,编译的时候不要报错,在链接的时候按照字符串寻址可以找到这个变量或者函数。(函数默认是外部类型的,不需要显示声明,但是变量必须,如果想把一个函数声明为只在本文件范围有效,那么可以用static来说明) 在某个头文件,比如A.h中定义了全局变量比如int a;,那么在其他文件中的函数调用变量a的时候需要在对应头文件或者定义文件中(保证在使用这个变量前)使用extern int a;..._extern变量多个文件中修改

推荐文章

热门文章

相关标签