相机参考引起问题

时间:2013-05-26 17:11:51

标签: android camera android-camera-intent

所以,我想为用户创建一个社交网络页面,他们可以在屏幕按钮选项中将它们带到他们选择的社交网络选项,在这个屏幕上我决定包含对相机的引用,但是当我在我的Java代码中包含相机时,我的应用程序将无法启动,当我发表评论时,它会启动,我是否遗漏了某些内容?

这是我的Java代码:

    package com.example.nxtremotecontroler;

    import android.app.Activity;
    import android.content.ComponentName;
    import android.content.ContentValues;
    import android.content.Intent;
    import android.content.pm.ActivityInfo;
    import android.net.Uri;
    import android.os.Bundle;
    import android.provider.MediaStore;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.ImageView;

    public class socialnetworking extends Activity {
Button email, options;
ImageView instagram, facebook, twitter, camerabtn;

@Override
public void onCreate(Bundle SavedInstanceState) {
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    super.onCreate(SavedInstanceState);
    setContentView(R.layout.socialnetworking);

    instagram = (ImageView) findViewById(R.id.instagrambtn);
    facebook = (ImageView) findViewById(R.id.facebookbtn);
    email = (Button) findViewById(R.id.emailbtn);
    twitter = (ImageView) findViewById(R.id.twitterbtn);
    options = (Button) findViewById(R.id.Options);

    email.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent emailIntent = new Intent(
                    android.content.Intent.ACTION_SEND);
            emailIntent.setType("text/plain");
            startActivity(emailIntent);
        }
    });

    facebook.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            try {

                Intent intent = new Intent(Intent.ACTION_VIEW, Uri
                        .parse("fb://?ref=tn_tnmn"));
                startActivity(intent);

            } catch (Exception e) {

                startActivity(new Intent(Intent.ACTION_VIEW, Uri
                        .parse("http://www.facebook.com/?ref=tn_tnmn")));
            }
        }
    });

    twitter.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View v){
            String url = "https://twitter.com/intent/tweet?source=webclient&text=TWEET+THIS!";
            Intent twitterIntent = new Intent(android.content.Intent.ACTION_VIEW);
            twitterIntent.setData(Uri.parse(url));
            startActivity(twitterIntent);
        }
    });

    instagram.setOnClickListener(new OnClickListener() {            
        @Override
        public void onClick(View v) {
            String url = "https://instagram.com/accounts/login/";
            Intent instagramIntent = new Intent(android.content.Intent.ACTION_VIEW);
            instagramIntent.setData(Uri.parse(url));
            startActivity(instagramIntent);
        }
    });

    options.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View v){
            Intent othersIntent = new Intent(android.content.Intent.ACTION_VIEW);
            othersIntent.setType("text/plain");
            startActivity(Intent.createChooser(othersIntent, "Choose one"));
        }
    });

    camerabtn.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View v){
            Intent intent = new Intent("android.intent.action.MAIN");
               intent.setComponent(ComponentName.unflattenFromString("com.google.android.camera/com.android.camera.Camera"));
               intent.addCategory("android.intent.category.LAUNCHER");
               startActivity(intent);
        }
    });
}
    }

如果需要我的XML或LogCat日志,请告诉我

1 个答案:

答案 0 :(得分:0)

你忘了做这样的事情:

camerabtn = (ImageView) findViewById(R.id.camerabtn);