我尝试通过选项菜单中的按钮启动手机的电子邮件应用时遇到问题,因为只要我点击模拟器中的按钮就会导致强制关闭错误。如果是这样。帮助我在这里找到我的代码中的错误,这将是伟大的。
这是我的java文件:
package com.mobilevideoeditor.moved;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;
public class ShareGalleryView extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videogrid);
GridView vGrid=(GridView) findViewById(R.id.vgrid);
registerForContextMenu(vGrid);
vGrid.setAdapter(new VideoAdapter(this));
vGrid.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
// TODO Auto-generated method stub
openOptionsMenu();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_gallery_share, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected (MenuItem item){
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
if (item.getItemId() == R.id.menu_facebook)
{
//TODO open fb
return true;
}
else if (item.getItemId() == R.id.menu_youtube)
{
//TODO open youtube
return true;
}
else if (item.getItemId() == R.id.menu_email)
{
startActivity(emailIntent);
return true;
}
else if (item.getItemId() == R.id.menu_bluetooth)
{
// TODO send via bluetooth
return true;
}
return super.onContextItemSelected(item);
}
public class VideoAdapter extends BaseAdapter {
private Context mContext;
public VideoAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_2,
R.drawable.sample_6, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_1
};
}
}
这就是DDMS打印出的内容:
07-16 01:05:55.782: WARN/System.err(2096): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND }
07-16 01:05:55.792: WARN/System.err(2096): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
07-16 01:05:55.812: WARN/System.err(2096): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
07-16 01:05:55.822: WARN/System.err(2096): at android.app.Activity.startActivityFromChild(Activity.java:2989)
07-16 01:05:55.822: WARN/System.err(2096): at android.app.Activity.startActivityForResult(Activity.java:2769)
07-16 01:05:55.832: WARN/System.err(2096): at android.app.Activity.startActivity(Activity.java:2855)
07-16 01:05:55.842: WARN/System.err(2096): at com.mobilevideoeditor.moved.ShareGalleryView.onOptionsItemSelected(ShareGalleryView.java:79)
07-16 01:05:55.842: WARN/System.err(2096): at android.app.Activity.onMenuItemSelected(Activity.java:2170)
07-16 01:05:55.842: WARN/System.err(2096): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:730)
07-16 01:05:55.852: WARN/System.err(2096): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:139)
07-16 01:05:55.852: WARN/System.err(2096): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
07-16 01:05:55.852: WARN/System.err(2096): at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:525)
07-16 01:05:55.862: WARN/System.err(2096): at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
07-16 01:05:55.862: WARN/System.err(2096): at android.view.View.onTouchEvent(View.java:4179)
07-16 01:05:55.872: WARN/System.err(2096): at android.widget.TextView.onTouchEvent(TextView.java:6541)
07-16 01:05:55.882: WARN/System.err(2096): at android.view.View.dispatchTouchEvent(View.java:3709)
07-16 01:05:55.882: WARN/System.err(2096): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-16 01:05:55.882: WARN/System.err(2096): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-16 01:05:55.882: WARN/System.err(2096): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
07-16 01:05:55.892: WARN/System.err(2096): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
07-16 01:05:55.902: WARN/System.err(2096): at android.os.Handler.dispatchMessage(Handler.java:99)
07-16 01:05:55.912: WARN/System.err(2096): at android.os.Looper.loop(Looper.java:123)
07-16 01:05:55.912: WARN/System.err(2096): at android.app.ActivityThread.main(ActivityThread.java:4363)
07-16 01:05:55.922: WARN/System.err(2096): at java.lang.reflect.Method.invokeNative(Native Method)
07-16 01:05:55.922: WARN/System.err(2096): at java.lang.reflect.Method.invoke(Method.java:521)
07-16 01:05:55.932: WARN/System.err(2096): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-16 01:05:55.932: WARN/System.err(2096): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-16 01:05:55.932: WARN/System.err(2096): at dalvik.system.NativeStart.main(Native Method)
07-16 01:05:55.992: WARN/InputManagerService(53): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@43cd4d30
答案 0 :(得分:3)
答案是堆栈跟踪告诉您的内容:您没有任何可以处理ACTION_SEND
Intent
的内容。
部分原因是"plain/text"
不是有效的MIME类型。试试"text/plain"
。而且,如果您要包含MIME类型,则实际上需要包含实际的电子邮件消息 - 您要声明的内容是纯文本。
有关使用ACTION_SEND
。
答案 1 :(得分:1)
要避免强制关闭对话框窗口,您必须实现错误处理。 在堆栈跟踪中,您将找到问题,发布堆栈跟踪。
public boolean onOptionsItemSelected (MenuItem item){
try{
...
...
...
}catch(Exception e)
{
e.PrintStackTrace();
}
return super.onContextItemSelected(item);
}