我开发了一个应用程序,我正在使用 LinkedIn 集成来共享文本和图像,它在 HTC 手机中运行良好,但不适用于所有三星手机。请解决我的问题
我的java代码..
Button b1 = (Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(),LinkedInPost.class);
startActivity(i);
}
}
LinkedInPost.java
public class LinkedInPost extends Activity
{
// initializations
public static final String CONSUMER_KEY = "key-key-key";
public static final String CONSUMER_SECRET = "key-key-key";
public static final String OAUTH_CALLBACK_SCHEME = "x-oauthflow-linkedin";
public static final String OAUTH_CALLBACK_HOST = "techgene";
public static final String OAUTH_CALLBACK_URL = OAUTH_CALLBACK_SCHEME + "://" + OAUTH_CALLBACK_HOST;
final LinkedInOAuthService oAuthService = LinkedInOAuthServiceFactory.getInstance().createLinkedInOAuthService(CONSUMER_KEY,CONSUMER_SECRET);
final LinkedInApiClientFactory factory = LinkedInApiClientFactory.newInstance(CONSUMER_KEY, CONSUMER_SECRET);
LinkedInRequestToken liToken;
LinkedInApiClient client;
private String strLinkedInMessage;
private String strLinkTitle;
private String strLink;
//Called when the activity is starting.
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.linkedin);
strLinkedInMessage = "04.17pm";
strLinkTitle = "testing";
strLink = "http://184.173.113.66/images/deal/rest_2012_3_18-0_1_27309-oysters-01.jpg";
liToken = oAuthService.getOAuthRequestToken(OAUTH_CALLBACK_URL);
try
{
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(liToken.getAuthorizationUrl()));
startActivity(i);
}
catch (Exception e)
{
Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_SHORT).show();
}
}
/**
* Method to verify the authentication, As it is used only in this package, it is made protected
*/
@Override
protected void onNewIntent(Intent intent)
{
try
{
String verifier = intent.getData().getQueryParameter("oauth_verifier");
LinkedInAccessToken accessToken = oAuthService.getOAuthAccessToken(liToken, verifier);
client = factory.createLinkedInApiClient(accessToken);
client.postShare(strLinkedInMessage, strLinkTitle,strLink, strLink,VisibilityType.CONNECTIONS_ONLY);
Toast.makeText(getBaseContext(), "In Try +ve", Toast.LENGTH_SHORT).show();
}
catch (Exception e)
{
Toast.makeText(getBaseContext(), "onNewIntent", Toast.LENGTH_SHORT).show();
}
finish();
}
清单.xml
<activity
android:name=".LinkedInPost"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="techgene"
android:scheme="x-oauthflow-linkedin" />
</intent-filter>
</activity>
此代码在 htc 中工作正常,但在 logcat 中无法在三星中工作我这样的错误
10-02 06:16:07.312: E/AndroidRuntime(11708): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.LinkedInPost}: com.google.code.linkedinapi.client.oauth.LinkedInOAuthServiceException: oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: api.linkedin.com
10-02 06:16:07.312: E/AndroidRuntime(11708): Caused by: com.google.code.linkedinapi.client.oauth.LinkedInOAuthServiceException: oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: api.linkedin.com
10-02 06:16:07.312: E/AndroidRuntime(11708): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:294)
10-02 06:16:07.312: E/AndroidRuntime(11708): at java.net.InetAddress.lookupHostByName(InetAddress.java:497)
10-02 06:16:07.312: E/AndroidRuntime(11708): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:69)