我正在实施一个应用程序,在点击“分享按钮”时将图像分享给whatsapp,根据这个项目,我创建了一个扩展Baseadapter的Imageadapter和一个用于共享图像的活动。所以,当我点击“分享按钮”时它应该生成“不支持文件格式化”。
ImageAdapter.java
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return mThumbIds[position];
}
public long getItemId(int position) {
return 0;
}
public ImageAdapter(Context c) {
mContext = c;
}
public View getView(final int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null){
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(80, 80));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(15, 15, 15, 15);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(mContext,FullScreenImage.class);
intent.putExtra("imageID", mThumbIds[position]);
mContext.startActivity(intent);
}
});
}
else{
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
private Integer[] mThumbIds = {
R.mipmap.h1, R.mipmap.h2,
R.mipmap.h3, R.mipmap.h4,
R.mipmap.h5,R.mipmap.h6,
R.mipmap.h7,R.mipmap.h8
,R.mipmap.h9,R.mipmap.h10
,R.mipmap.h11,R.mipmap.h12
,R.mipmap.h13,R.mipmap.h14
,R.mipmap.h15
};
}
FullScreenImage.java
public class FullScreenImage extends Activity {
ImageView imageView,imgBack;
Button setWallpaper,share;
Context activity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_fullscreen_image);
//Get image fro Image adapter
Bundle bdl = getIntent().getExtras();
final int imageRes = bdl.getInt("imageID");
//Setting up imageview
imageView = (ImageView)findViewById(R.id.imgDisplay);
//Share image to whatsapp
share = (Button)findViewById(R.id.btnShare);
share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri imageUri = Uri.parse("android.resource://com.v1.sensoft.halloween/mipmap"+imageRes);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(intent , "Share"));
}
});
//Setting up wallpaper
ImageView image = (ImageView) findViewById(R.id.imgDisplay);
image.setImageResource(imageRes);
setWallpaper = (Button)findViewById(R.id.setWall);
setWallpaper.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
WallpaperManager myWallpaperManager
= WallpaperManager.getInstance(getApplicationContext());
try {
myWallpaperManager.setResource(imageRes);
Context context = getApplicationContext();
// Create layout inflator object to inflate toast.xml file
LayoutInflater inflater = getLayoutInflater();
// Call toast.xml file for toast layout
View toastRoot = inflater.inflate(R.layout.layout_toast2, null);
Toast toast = new Toast(context);
// Set layout to toast
toast.setView(toastRoot);
toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL,
0,0 );
toast.setDuration(Toast.LENGTH_LONG);
toast.show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
//Header back button...for Mainactivity.java
imgBack = (ImageView)findViewById(R.id.imgBack);
imgBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intentLog9 = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intentLog9);
finish();
}
});
}
}
如果有人知道这是什么问题,请告诉我。 提前谢谢......
答案 0 :(得分:3)
尝试将.jpg附加到图像文件名。 fileName应具有有效的图像名称扩展名,如.jpg或.jpeg。
在onClick上尝试实现以下代码:
Intent intent = new Intent(mContext,FullScreenImage.class);
intent.putExtra("imageID", mThumbIds[position]+".jpg");
mContext.startActivity(intent);
答案 1 :(得分:1)
update tab t
set ProductGroup = 'Product C'
where exists (
select 1
from tab tt
where exists ( select Invoice
from tab
where Invoice = tt.Invoice
group by Invoice
having count(*)>1 )
or exists ( select Customer
from tab
where Customer = tt.Customer
group by Customer
having count(*)>1 ) )
您必须从url下载图像到sdcard;将sdcard的路径发送到whatsapp
答案 2 :(得分:0)
您可以使用以下代码段仅将图片分享到whatsapp;
Uri imageUri = Uri.parse("android.resource://com.v1.sensoft.halloween/mipmap"+imageRes);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
//Target whatsapp:
shareIntent.setPackage("com.whatsapp");
//Add Image URI
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(shareIntent);
答案 3 :(得分:0)
我明白了你的意思。在你的情况下,首先你必须在sdcard里面的Asynctask商店的帮助下从Uri下载图像,并使用以下代码发送到该图像
当您从SD卡中选择路径时,它将自动检测图像扩展本身,无需担心
try {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
sendIntent.putExtra(Intent.EXTRA_TEXT, "your title");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("your image path"));
sendIntent.setType("image/*");
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
} catch (Exception e) {
e.printStackTrace();
}