整合ForGooglePlus活動在你的代碼,並把URL(IMAGEURL),描述(description文本)和的contentURL(URL),對於相同的。 注意:波紋管代碼也適用於我的應用程序。
public class ForGooglePlus extends Activity
{
private String imageUrl, description, contentUrl;
private Context mContext;
private int REQUEST_FOR_GOOGLE_PLUS = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
mContext = this;
imageUrl = getIntent().getStringExtra("URL");
description = getIntent().getStringExtra("Description");
contentUrl = getIntent().getStringExtra("contentUrl");
if (isPackageInstalled("com.google.android.apps.plus", mContext)) {
if (imageUrl == null) {
imageUrl = "";
}
if (description == null) {
description = "";
}
// Intent shareIntent = new PlusShare.Builder(this)
// .setType("image/jpeg")
// .setText(description)
// .setStream(getUriFromUrl(imageUrl))
// .setContentUrl(Uri.parse(contentUrl))
// .getIntent();
Uri uri = getUriFromUrl(imageUrl);
if (uri != null) {
Intent shareIntent = ShareCompat.IntentBuilder
.from(ForGooglePlus.this)
.setText(description + "\n" + contentUrl)
.setType("image/jpeg").setStream(uri).getIntent()
.setPackage("com.google.android.apps.plus");
startActivityForResult(shareIntent, REQUEST_FOR_GOOGLE_PLUS);
} else {
Intent shareIntent = ShareCompat.IntentBuilder
.from(ForGooglePlus.this)
.setText(description + "\n" + contentUrl)
.setType("image/jpeg").getIntent()
.setPackage("com.google.android.apps.plus");
startActivityForResult(shareIntent, REQUEST_FOR_GOOGLE_PLUS);
}
} else {
Toast.makeText(mContext, "Application not found", Toast.LENGTH_LONG)
.show();
finish();
}
}
public Uri getUriFromUrl(String thisUrl) {
try {
Bitmap inImage = ImageLoader.getInstance().loadImageSync(thisUrl);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = Images.Media.insertImage(
mContext.getContentResolver(), inImage, "Title", null);
return Uri.parse(path);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return null;
}
private boolean isPackageInstalled(String packagename, Context context) {
PackageManager pm = context.getPackageManager();
try {
pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
return true;
} catch (NameNotFoundException e) {
return false;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_FOR_GOOGLE_PLUS) {
if (resultCode == RESULT_OK) {
finish();
} else {
Toast.makeText(mContext,
mContext.getString(R.string.msg_gp_cancel),
Toast.LENGTH_LONG).show();
finish();
}
}
}
}
檢查日誌? – pedrofurla
當應用程序啓動時,它顯示烤麪包上有一條消息「你只能在你的SD卡上張貼照片禮物」。但我正在給sd-card的照片地址。有什麼問題我不理解? –
@DeepikaLalra我有類似的問題。你能建議嗎? – Apparatus