簡體   English   中英

相機參考引起問題

[英]Camera reference is causing problems

因此,我想為用戶創建一個社交網絡頁面,讓他們在屏幕上具有按鈕選項,以將他們帶到他們選擇的社交網絡選項,並且在此屏幕上,我決定包括對攝像機的引用,但是當我包含我的應用程序中的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日志,請告訴我

您忘了做這樣的事情:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM