首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android ShareActionProvider在调试模式下工作,但在实际设备中不工作。

Android ShareActionProvider在调试模式下工作,但在实际设备中不工作。
EN

Stack Overflow用户
提问于 2013-10-21 15:21:36
回答 2查看 1.2K关注 0票数 5

当我在设备上使用Eclipse调试我的应用程序时,这就是我想要的结果:

来自调试模式的App映像

“共享图标”运行良好!

这里,问题出在这里!当我在GOOGLE上添加应用程序,然后从IT安装应用程序时,结果是:

从Google安装后的应用程序图像

‘共享图标’不起作用。它是可点击的,但它什么也不做。图标没有出现,只是标题:“共享”

这是代码:

代码语言:javascript
复制
private ShareActionProvider mShareActionProvider;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);
    // Set up ShareActionProvider's default share intent
    MenuItem shareItem = menu.findItem(R.id.action_share);
    mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem);
    mShareActionProvider.setShareIntent(getDefaultShareIntent());  
    return super.onCreateOptionsMenu(menu);
}

private Intent getDefaultShareIntent() {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.app_name));
    intent.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.app_play_address));
    return intent;
}

这是main.xml文件:

代码语言:javascript
复制
<menu 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:yourapp="http://schemas.android.com/apk/res-auto">

<item 
    android:id="@+id/action_share"
    android:title="@string/share"
    yourapp:showAsAction="ifRoom"
    yourapp:actionProviderClass="android.support.v7.widget.ShareActionProvider" />

</menu>

在styles.xml文件中:

代码语言:javascript
复制
<resources>

<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="@style/Theme.AppCompat">
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

V-11中的styles.xml文件:

代码语言:javascript
复制
<resources>

<!--
    Base application theme for API 11+. This theme completely replaces
    AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="@style/Theme.AppCompat">
    <!-- API 11 theme customizations can go here. -->
</style>

V-14中的styles.xml文件:

代码语言:javascript
复制
<resources>

<!--
    Base application theme for API 14+. This theme completely replaces
    AppBaseTheme from BOTH res/values/styles.xml and
    res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="@style/Theme.AppCompat">
    <!-- API 14 theme customizations can go here. -->
</style>

最后,在manifest.xml上:

代码语言:javascript
复制
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-05-16 14:59:06

你是在用Pro卫兵来释放你吗?

是的,我也遇到了同样的问题,直到我意识到ShareActionProvider的课被Pro卫兵弄坏了,所以我不得不把它从门卫的残缺中拿出来。

因此,在proguard-project.txt中,包括以下一行:

代码语言:javascript
复制
-keep class android.support.v7.widget.ShareActionProvider { *; }
票数 16
EN

Stack Overflow用户

发布于 2013-10-21 15:33:33

您的清单中有正确的权限吗?

http://developer.android.com/guide/topics/security/permissions.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19498489

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档