gpt4 book ai didi

android - java.lang.IllegalArgumentException : menu item with ID 2131558727 doesn't have a MediaRouteActionProvider

转载 作者:行者123 更新时间:2023-12-01 07:12:40 25 4
gpt4 key购买 nike

嗨,我正在将 chromecast 功能集成到我现有的应用程序中。我有以下代码:

public class VideoBrowserActivity extends AppCompatActivity {

private static final String TAG = "VideoBrowserActivity";
private boolean mIsHoneyCombOrAbove = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
private Toolbar mToolbar;
private CastContext mCastContext;
private MenuItem mediaRouteMenuItem;
private IntroductoryOverlay mIntroductoryOverlay;
private CastStateListener mCastStateListener;

/*
* (non-Javadoc)
* @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video_browser);
setupActionBar();

mCastStateListener = new CastStateListener() {
@Override
public void onCastStateChanged(int newState) {
if (newState != CastState.NO_DEVICES_AVAILABLE) {
Log.e("DEBUG","===");
showIntroductoryOverlay();
}
}
};

mCastContext = CastContext.getSharedInstance(this);
}

@Override
protected void onResume() {
mCastContext.addCastStateListener(mCastStateListener);
super.onResume();
}

@Override
protected void onPause() {
mCastContext.removeCastStateListener(mCastStateListener);
super.onPause();
}


private void setupActionBar() {
mToolbar = (Toolbar) findViewById(R.id.toolbar);
mToolbar.setTitle(R.string.app_name);
setSupportActionBar(mToolbar);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.browse, menu);
mediaRouteMenuItem = CastButtonFactory.setUpMediaRouteButton(getApplicationContext(), menu,
R.id.media_route_menu_item);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent i;
switch (item.getItemId()) {
case R.id.action_settings:
i = new Intent(VideoBrowserActivity.this, CastPreference.class);
startActivity(i);
break;
}
return true;
}

@Override
protected void onDestroy() {
Log.d(TAG, "onDestroy is called");
super.onDestroy();
}


private void showIntroductoryOverlay() {
if (mIntroductoryOverlay != null) {
mIntroductoryOverlay.remove();
}
if ((mediaRouteMenuItem != null) && mediaRouteMenuItem.isVisible()) {
new Handler().post(new Runnable() {
@Override
public void run() {
mIntroductoryOverlay = new IntroductoryOverlay.Builder(
VideoBrowserActivity.this, mediaRouteMenuItem)
.setTitleText("Introducing Cast")
.setSingleTime()
.setOnOverlayDismissedListener(
new IntroductoryOverlay.OnOverlayDismissedListener() {
@Override
public void onOverlayDismissed() {
mIntroductoryOverlay = null;
}
})
.build();
mIntroductoryOverlay.show();
}
});
}
}
}

这些是xml文件

浏览器.xml
<?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/media_route_menu_item"
android:title="@string/media_route_menu_title"
app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
app:showAsAction="always"/>

<item
android:id="@+id/action_settings"
android:title="@string/action_settings"
app:showAsAction="never"/>

</menu>

和expanded_controller.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/media_route_menu_item"
android:title="@string/media_route_menu_title"
app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
app:showAsAction="always"/>

</menu>

当我运行此代码时,我收到以下错误

j
ava.lang.IllegalArgumentException: menu item with ID 2131558727 doesn't have a MediaRouteActionProvider.
at com.google.android.gms.cast.framework.CastButtonFactory.setUpMediaRouteButton(Unknown Source)
at com.calkins.tv_everywhere.VideoBrowserActivity.onCreateOptionsMenu(VideoBrowserActivity.java:1168)
at android.app.Activity.onCreatePanelMenu(Activity.java:3128)
at com.android.internal.policy.PhoneWindow.preparePanel(PhoneWindow.java:648)
at com.android.internal.policy.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:1029)
at com.android.internal.policy.PhoneWindow$1.run(PhoneWindow.java:341)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7231)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

为什么会出现这个错误,我很困惑。任何帮助...

最佳答案

如果您正在构建具有 minifyEnabled true 的发布 apk,
将这些行添加到您的 proguard 文件中

-keep class android.support.v7.app.MediaRouteActionProvider{
*;
}
-keep class androidx.mediarouter.app.MediaRouteActionProvider{
*;
}

关于android - java.lang.IllegalArgumentException : menu item with ID 2131558727 doesn't have a MediaRouteActionProvider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43492157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com