的Android ShareActionProvider工作,但并没有在实际设备

问题描述:

当调试我的设备上的应用程序,使用Eclipse,这是结果,这就是我想要的:的Android ShareActionProvider工作,但并没有在实际设备

App image from debug mode

“共享图标'工作正常!

这里,问题!!!!当我添加的Google Play应用程序,然后我安装应用程序从IT,这是结果:

App image after install from Google Play

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

这是代码:

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中的文件:

<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文件:

<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 0

styles.xml的文件:在V-14

<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> 

styles.xml文件:

<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 :

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

你使用ProGuard为您发布?

我也有同样的问题,直到我意识到类ShareActionProvider被Proguard弄坏了,因此我不得不将它从Proguard中删除。

所以,在你的ProGuard-project.txt,包括以下行:

-keep class android.support.v7.widget.ShareActionProvider { *; } 

您的清单中是否拥有正确的权限?

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

+0

什么权限? –

+0

我需要权限才能使用“ShareActionProvider”? –

+0

在这里检查http://developer.android.com/training/sharing/shareaction.html –