I have tried to implement a share button in an android app using the v7.support libraries and not using them. I am trying to use this code, but it throws NPE on getActionProvider:
WebView webs = (WebView)findViewById(R.id.welcomeWebview);
ShareCompat.IntentBuilder b = ShareCompat.IntentBuilder.from(this).setType("text/html").setHtmlText(webs.getUrl());
getMenuInflater().inflate(R.menu.menu_main, menu);
MenuItem item = (MenuItem) findViewById(R.id.menu_item_share);
Intent intent = b.getIntent();
MenuItemCompat.getActionProvider(item);
ShareActionProvider mShareActionProvider = (ShareActionProvider)item.getActionProvider();
mShareActionProvider.setShareIntent(intent);
Here is my relevant XML.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.tgwf.www.tgwf" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
And the LogCat stack is here :
11-02 06:17:50.005 11198-11198/org.tgwf.www.tgwf E/SysUtils: ApplicationContext is null in ApplicationStatus
11-02 06:17:50.063 11198-11198/org.tgwf.www.tgwf E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)
11-02 06:17:50.063 11198-11198/org.tgwf.www.tgwf E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)
11-02 06:17:50.132 11198-11198/org.tgwf.www.tgwf E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008d57
11-02 06:17:50.199 11198-11198/org.tgwf.www.tgwf E/DataReductionProxySettingListener: No DRP key due to exception:java.lang.ClassNotFoundException: com.android.webview.chromium.Drp