新手在这里。我有一个应用程序,我正在处理所有图像视图,一切运行正常,但我遇到的问题是,我似乎无法在电子邮件中打开图像或在文本消息中附加电子邮件,因为它们两种状态,使用共享意图方法。它将显示我附加的文本,它发送得很好,但我可以打开或附加图像。我在manifest中添加了write_external方法。希望有人可以帮我解决这个问题。代码在下面,但共享意图部分有点乱,因为我有2个差异代码在那里运行与图像的共享意图..两个工作正常..没有错误...但没有打开或通过文本或电子邮件附加图像。
package com.app.appname;
import android.app.ActionBar;
import android.content.Intent;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Spannable;
import android.text.SpannableString;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdRequest.Builder;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import java.io.File;
import static com.app.appname.R.id.adView;
public class imageView1 extends AppCompatActivity {
private ImageView imgview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.imageview1);
SpannableString s = new SpannableString("Action Bar Title");
s.setSpan(new TypefaceSpan(this, "Sui.ttf"), 0, s.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// Update the action bar title with the TypefaceSpan instance
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setTitle(s);
AdView mAdView = (AdView) findViewById(adView);
AdRequest adRequest = new AdRequest.Builder()
.build();
mAdView.loadAd(adRequest); }
public void shareText(View view) {
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
intent.setType("image/jpeg");
String shareBodyText = "Sharing message goes here";
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject/Title");
intent.putExtra(android.content.Intent.EXTRA_TEXT, shareBodyText);
startActivity(Intent.createChooser(intent, "Choose sharing method"));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.action_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.share:
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
Uri imageUri = Uri.parse("android.resource://com.app.appname/pic1.jpg");
Log.i("imageUri",""+imageUri);
share.putExtra(Intent.EXTRA_STREAM,imageUri);
startActivity(Intent.createChooser(share, "Share Image"));
Uri u = Uri.parse("android.resource://com.app.appname/pic1.jpg");
File f = new File("" + u);
f.getName();
sharingIntent.setType("image/jpeg");
Uri uri = Uri.parse("android.resource://com.app.appname/"+R.drawable.pic1);
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
String shareBodyText = "Download app from ";
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "App Name");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBodyText);
startActivity(Intent.createChooser(sharingIntent, "Share via"));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}