我尝试将图片的ID从活动发送到另一个活动。但不幸的是停了下来。但我找不到任何解决方案。这是我的主要活动。我将所有图片ID保存在Utils类中。
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
Intent intent=new Intent(MainActivity.this,SendActivity.class);
intent.putExtra("id",Utils.THUMBNAIL_IDS[position]);
startActivity(intent);
}
});
这是我的sendActivity,我试图将此图像分享给Messenger: Intent intent = getIntent(); 位置= getIntent()getExtras()getInt( “ID”);
现在要分享给messenger的代码:
private void onMessengerButtonClicked() {
// The URI can reference a file://, content://, or android.resource. Here we use
// android.resource for sample purposes.
Uri uri = Uri.parse("android.resource://com.example.amit.bengalistickerfun/drawable/" +
MainActivity.mAdapter.getItem(position));
// Create the parameters for what we want to send to Messenger.
ShareToMessengerParams shareToMessengerParams =
ShareToMessengerParams.newBuilder(uri, "image/jpeg")
.setMetaData("{ \"image\" : \"tree\" }")
.build();
// Sharing from an Activity
MessengerUtils.shareToMessenger(this, 0, shareToMessengerParams);
if (mPicking) {
// If we were launched from Messenger, we call MessengerUtils.finishShareToMessenger to return
// the content to Messenger.
MessengerUtils.finishShareToMessenger(this, shareToMessengerParams);
} else {
// Otherwise, we were launched directly (for example, user clicked the launcher icon). We
// initiate the broadcast flow in Messenger. If Messenger is not installed or Messenger needs
// to be upgraded, this will direct the user to the play store.
MessengerUtils.shareToMessenger(
this,
REQUEST_CODE_SHARE_TO_MESSENGER,
shareToMessengerParams);
}
有人能帮助我吗?
答案 0 :(得分:1)
我建议在这里放置try catch块,以便捕获异常。如果有的话
尝试观察log-cat并查看错误
尝试使用android内置日志记录类查看日志
在此处发布您的错误日志,以便我们可以查看问题并相应地提供输入。