2016-08-25 15 views
0

저는 단순한 PanoramaView를 가지고있는 단순한 VR 어플리케이션을 개발하려고합니다. 저는 약간의 플로팅 버튼을 추가 할 것입니다 (나중에). 하지만 지금 문제는 : 안드로이드 SDK에 대한 Google 튜토리얼을 따라 왔지만, 화면에서 앱을 실행하려고하면 완전히 검은 색입니다. `VrPanoramaView는 어떤 이미지도 보여주지 않습니다.

public class MainActivity extends Activity { 

    private static final String LOG_TAG = MainActivity.class.getSimpleName(); 

    private VrPanoramaView panoWidgetView; 
    public boolean loadImageSuccessful; 

    //** Tracks the file to be loaded across the lifetime of this app. **/ 
    private Uri fileUri; 
    /** Configuration information for the panorama. **/ 
    private VrPanoramaView.Options panoOptions = new VrPanoramaView.Options(); 
    private ImageLoaderTask backgroundImageLoaderTask; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     panoWidgetView = (VrPanoramaView)findViewById(R.id.pano_view); 
     panoWidgetView.setEventListener(new ActivityEventListener()); 
    } 

    protected void onNewIntent(Intent intent) { 
     Log.i(LOG_TAG, this.hashCode() + ".onNewIntent()"); 

     setIntent(intent); 

     handleIntent(intent); 
    } 

    private void handleIntent(Intent intent) { 
     //Controllo che l'intent abbia un file da caricare 
     if(Intent.ACTION_VIEW.equals(intent.getAction())) { 
      Log.i(LOG_TAG,"ACTION VIEW RECEIVED"); 
      fileUri = intent.getData(); 
      if(fileUri == null) { 
       Log.w(LOG_TAG, "No data uri specified. Use \"-d /path/filename\"."); 
      } else { 
       Log.i(LOG_TAG, "Using file " + fileUri.toString()); 
      } 
      panoOptions.inputType = intent.getIntExtra("inputType", VrPanoramaView.Options.TYPE_MONO); 
      Log.i(LOG_TAG, "Options.inputType = " + panoOptions.inputType); 
     } else { 
      Log.i(LOG_TAG, "Intent is not ACTION_VIEW. Using default pano image."); 
      fileUri = null; 
      panoOptions.inputType = VrPanoramaView.Options.TYPE_MONO; 
     } 

     // Load the bitmap in a background thread to avoid blocking the UI thread 

     if (backgroundImageLoaderTask == null) { 
      backgroundImageLoaderTask.cancel(true); 
     } 
     backgroundImageLoaderTask = new ImageLoaderTask(); 
     backgroundImageLoaderTask.execute(Pair.create(fileUri, panoOptions)); 
    } 
    @Override 
    protected void onPause() { 
     panoWidgetView.pauseRendering(); 
     super.onPause(); 
    } 

    @Override 
    protected void onResume() { 
     super.onResume(); 
     panoWidgetView.resumeRendering(); 
    } 

    @Override 
    protected void onDestroy() { 
     // Destroy the widget and free memory. 
     panoWidgetView.shutdown(); 

     // The background task has a 5 second timeout so it can potentially stay alive for 5 seconds 
     // after the activity is destroyed unless it is explicitly cancelled. 
     if (backgroundImageLoaderTask != null) { 
      backgroundImageLoaderTask.cancel(true); 
     } 
     super.onDestroy(); 
    } 
    class ImageLoaderTask extends AsyncTask<Pair<Uri, VrPanoramaView.Options>, Void, Boolean> { 
     VrPanoramaView.Options panoOptions = null; // It's safe to use null VrPanoramaView.Options. 
     InputStream istr = null; 

     @Override 
     protected Boolean doInBackground(Pair<Uri, VrPanoramaView.Options>... information) { 

      if(information == null || information.length < 1 || information[0] == null || information[0].first == null) { 
       AssetManager assetManager = getAssets(); 
       try { 
        istr = assetManager.open("andes.jpg"); 
        panoOptions = new VrPanoramaView.Options(); 
        panoOptions.inputType = VrPanoramaView.Options.TYPE_STEREO_OVER_UNDER; 

       } catch (IOException e) { 
        Log.e(LOG_TAG,"asjdsd"+ e); 
        e.printStackTrace(); 
        return false; 
       } 
      } else { 
       try { 
        istr = new FileInputStream(new File(information[0].first.getPath())); 
       } catch (FileNotFoundException e) { 
        Log.e(LOG_TAG, "aopsjodiajs" + e); 
        e.printStackTrace(); 
       } 
      } 
      try { 
       istr.close(); 
      } catch (IOException e) { 
       Log.e(LOG_TAG, "asdasd" + e); 
       e.printStackTrace(); 
       return false; 
      } 
      return true; 
     } 

     @Override 
     protected void onPostExecute(Boolean aBoolean) { 
      if(istr != null && panoOptions != null) { 
       panoWidgetView.loadImageFromBitmap(BitmapFactory.decodeStream(istr),panoOptions); 
      } 
      super.onPostExecute(aBoolean); 
     } 
    } 
    private class ActivityEventListener extends VrPanoramaEventListener { 

     public void onLoadSuccess() { 
      loadImageSuccessful = true; 
     } 
     @Override 
     public void onLoadError(String errorMessage) { 
      loadImageSuccessful = false; 
      Toast.makeText(
        MainActivity.this, "Error loading pano: " + errorMessage, Toast.LENGTH_LONG) 
        .show(); 
      Log.e(LOG_TAG, "Error loading pano: " + errorMessage); 
     } 
    } 
} 

매니페스트 파일 : 여기

코드의

<?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="sgrumo.realestate"> 
     <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="24" /> 
     <uses-permission android:name="android.permission.NFC" /> 
     <uses-permission android:name="android.permission.VIBRATE" /> 
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

     <application 
      android:allowBackup="true" 
      android:icon="@mipmap/ic_launcher" 
      android:label="@string/app_name" 
      android:supportsRtl="true" 
      android:theme="@style/AppTheme"> 
      <activity 
       android:name=".MainActivity" 
       android:screenOrientation="landscape"> 
       <intent-filter> 
        <action android:name="android.intent.action.MAIN" /> 
        <category android:name="android.intent.category.LAUNCHER" /> 
        <category android:name="com.google.intent.category.CARDBOARD" /> 
       </intent-filter> 
      </activity> 
      <activity android:name=".OtherActivity" 
       android:screenOrientation="landscape"></activity> 
     </application> 

    </manifest> 

build.gradle :

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 24 
    buildToolsVersion "24.0.1" 

    defaultConfig { 
     applicationId "sgrumo.realestate" 
     minSdkVersion 23 
     targetSdkVersion 24 
     versionCode 1 
     versionName "1.0" 
     jackOptions { 
      enabled true 
     } 
    } 
    compileOptions { 
     sourceCompatibility org.gradle.api.JavaVersion.VERSION_1_8 
     targetCompatibility org.gradle.api.JavaVersion.VERSION_1_8 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:24.1.1' 
    compile project(':common') 
    compile project(':commonwidget') 
    compile project(':panowidget') 
    compile project(':base') 
} 

mainActivity 코드는 구글에서 제공하는 것과 그렇게 다르지 않다 , 나는 아직도 오류가 어디 있지 않습니다.

내 andes.jpg 파일은 assets 폴더에 있습니다.

답변

0

오류를 발견했습니다. OnCreate() 메서드에서 handleIntent (intent) 호출을 넣는 것을 잊었습니다!

관련 문제