Alte Codes für das Teilen funktioniert nicht mehr in API 23 oben.Ich lade das Bild in einem TouchImageView von der URL und ich möchte das Bild zu WhatsApp, Facebook etc. Ich konnte nicht finden keine verlässlichen neuen Codes in Internet und ich versuchte, einige Methoden zu teilen, aber alle von ihnen failed.Here ist mein CodeBild von URL zu Facebook, WhatsApp teilen
public class GalleryActivityshare extends DialogFragment
{
TouchImageView iv;
String url;
static GalleryActivityshare newInstance() {
GalleryActivityshare f = new GalleryActivityshare();
return f;
}
@Override
public void onStart()
{
super.onStart();
Dialog dialog = getDialog();
if (dialog != null)
{
int width = ViewGroup.LayoutParams.MATCH_PARENT;
int height = ViewGroup.LayoutParams.MATCH_PARENT;
dialog.getWindow().setLayout(width, height);
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.activity_galleryshare, container, false);
url=getArguments().getString("url");
iv = (TouchImageView) v.findViewById(R.id.imgDisplay);
new ImageLoadTask(url,iv).execute();
return v;
}
public void share(Context context, Uri bmpUri) throws IOException {
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.id.imgDisplay);
File file = new File(getActivity().getCacheDir(), String.valueOf(largeIcon
+ ".png"));
FileOutputStream fOut = new FileOutputStream(file);
largeIcon.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();
file.setReadable(true, false);
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
intent.setType("image/png");
startActivity(intent);
}
}
XML
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<com.touchlive.info.paramount.util.TouchImageView
android:id="@+id/imgDisplay"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter" />
<ImageView
android:tint="#123654"
android:onClick="share"
android:id="@+id/shared"
android:src="@drawable/share"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_width="40dp"
android:layout_height="40dp" />
Verwenden LogCat den Java-Stack-Trace mit Ihrer App verbunden zu untersuchen: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare
i änderte den Code, bitte schauen Sie – almiters