' URI未注册'添加新活动后

时间:2015-12-07 13:51:46

标签: android android-studio

我试图将示例活动添加到现有项目中。该项目与Gradle编译良好,但在我将活动声明添加到清单后, 已编译的清单在http://schemas.android.com/apk/res/android处为红色,其中包含未注册' URI的浮动消息。

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.YouTuber" >

<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:label="@string/action_bar_demo_name"
        android:name=".ActionBarDemoActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:screenOrientation="sensorLandscape">
        <meta-data android:name="@string/minVersion" android:value="11"/>
        <meta-data android:name="@string/isLaunchableActivity" android:value="true"/>
    </activity>

</application>

添加的活动是从YouTube API示例项目中获取的actionBarDemoActivity。

/*
 * Copyright 2012 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.YouTuber;

import android.annotation.TargetApi;
import android.app.ActionBar;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.KalromSystems.YouTuber.YouTuber.DeveloperKey;
import com.KalromSystems.YouTuber.YouTuber.YouTubeFailureRecoveryActivity;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerFragment;

import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;

/**
 * A sample showing how to use the ActionBar as an overlay when the video is playing in fullscreen.
 *
 * The ActionBar is the only view allowed to overlay the player, so it is a useful place to put
 * custom application controls when the video is in fullscreen. The ActionBar can not change back
 * and forth between normal mode and overlay mode, so to make sure our application's content
 * is not covered by the ActionBar we want to pad our root view when we are not in fullscreen.
 */
@TargetApi(11)
public class ActionBarDemoActivity extends YouTubeFailureRecoveryActivity implements
    YouTubePlayer.OnFullscreenListener {

  private ActionBarPaddedFrameLayout viewContainer;
  private YouTubePlayerFragment playerFragment;
  private View tutorialTextView;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.action_bar_demo);

    viewContainer = (ActionBarPaddedFrameLayout) findViewById(R.id.view_container);
    playerFragment =
        (YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.player_fragment);
    tutorialTextView = findViewById(R.id.tutorial_text);
    playerFragment.initialize(DeveloperKey.DEVELOPER_KEY, this);
    viewContainer.setActionBar(getActionBar());

    // Action bar background is transparent by default.
    getActionBar().setBackgroundDrawable(new ColorDrawable(0xAA000000));
  }

  @Override
  public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
      boolean wasRestored) {
    player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT);
    player.setOnFullscreenListener(this);

    if (!wasRestored) {
      player.cueVideo("9c6W4CCU9M4");
    }
  }

  @Override
  protected YouTubePlayer.Provider getYouTubePlayerProvider() {
    return (YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.player_fragment);
  }

  @Override
  public void onFullscreen(boolean fullscreen) {
    viewContainer.setEnablePadding(!fullscreen);

    ViewGroup.LayoutParams playerParams = playerFragment.getView().getLayoutParams();
    if (fullscreen) {
      tutorialTextView.setVisibility(View.GONE);
      playerParams.width = MATCH_PARENT;
      playerParams.height = MATCH_PARENT;
    } else {
      tutorialTextView.setVisibility(View.VISIBLE);
      playerParams.width = 0;
      playerParams.height = WRAP_CONTENT;
    }
  }

  /**
   * This is a FrameLayout which adds top-padding equal to the height of the ActionBar unless
   * disabled by {@link #setEnablePadding(boolean)}.
   */
  public static final class ActionBarPaddedFrameLayout extends FrameLayout {

    private ActionBar actionBar;
    private boolean paddingEnabled;

    public ActionBarPaddedFrameLayout(Context context) {
      this(context, null);
    }

    public ActionBarPaddedFrameLayout(Context context, AttributeSet attrs) {
      this(context, attrs, 0);
    }

    public ActionBarPaddedFrameLayout(Context context, AttributeSet attrs, int defStyle) {
      super(context, attrs, defStyle);
      paddingEnabled = true;
    }

    public void setActionBar(ActionBar actionBar) {
      this.actionBar = actionBar;
      requestLayout();
    }

    public void setEnablePadding(boolean enable) {
      paddingEnabled = enable;
      requestLayout();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
      int topPadding =
          paddingEnabled && actionBar != null && actionBar.isShowing() ? actionBar.getHeight() : 0;
      setPadding(0, topPadding, 0, 0);

      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

  }

}

控制台错误与minVersion有关: 错误:(33,31)找不到与给定名称匹配的资源(名称&#39;值为&#39; @ string / minVersion&#39;)。

看起来只是一种症状。

1 个答案:

答案 0 :(得分:1)

确保minVersion中包含名为isLaunchableActivitystring.xml的字符串。

此外,这些字符串应具有唯一的名称。所以你应该使用你的包名。因此,它们的名称类似于com.example.YouTuber.minVersioncom.example.YouTuber.isLaunchableActivity

另见http://developer.android.com/guide/topics/manifest/meta-data-element.html