0
我創建它使用相機,其中,當用戶需要他設有Shareactionprovider
(API級別16+)來共享圖像相片應用程式...應用崩潰,同時使用Shareactionprovider
由於shareactionprovider
具有出現在用戶需要的照片必須是在onPrepareoptionsmenu()
後...
我用下面的代碼,但應用程序崩潰.... 如果我不使用onPrepareoptionsmenu()
的應用程序工作正常但後來我不能獲取Shareactionprovider
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.camera, menu);
return true;
}
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
invalidateOptionsMenu();
getMenuInflater().inflate(R.menu.camera, menu);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// Locate MenuItem with ShareActionProvider
MenuItem item = menu.findItem(R.id.menu_share);
// Fetch and store ShareActionProvider
mShareActionProvider = (ShareActionProvider) item
.getActionProvider();
doShare();
Toast.makeText(this, "prepare", Toast.LENGTH_SHORT).show();
}
return super.onPrepareOptionsMenu(menu);
}
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void doShare() {
try {
if (file.exists() && file.length() > 0) {
// Populate the share intent with data
Intent intent = new Intent(Intent.ACTION_SEND);
mImageUri = Uri.fromFile(file);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, mImageUri);
mShareActionProvider.setShareIntent(intent);
} else
Toast.makeText(
this,
"You cancelled the image capture!!!! Please take image in order to Share",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(this, "Please take image in order to Share",
Toast.LENGTH_SHORT).show();
}
}
我該怎麼辦?
能否請你分享logcat的碰撞痕跡? – gunar