2013-04-18 6 views
1

Я работаю над приложением, и в tabhost у меня есть настройка настройки активности. Я интегрирую твиттер, facebook и linkedin в своем приложении. Теперь у меня есть проблема, что в linkedinИнтеграция Linkedin onNewIntent() не вызывается в андроидных вкладках

@Override 
protected void onNewIntent(Intent intent) 
{ 
    Log.v("finish", "finish Authenticate.."); 

    finishAuthenticate(intent.getData()); 
} 

не называется, потому что я использовал табуст. без tabhost он прекрасно работает ..

Я применить изменения в файле манифеста на Android: launchMode = "SingleTop" и андроида: launchMode = "singleTask" также Android: launchMode = "SingleInstance" BT это не работает вообще ..

ответ

0

После код работает идеально подходит для меня

следуя код я сделал это успешно 100% тестирование

public class ShareInLinkedIn extends Activity implements OnClickListener { 

private LinkedInOAuthService oAuthService; 
private LinkedInApiClientFactory factory; 
private LinkedInRequestToken liToken; 
private LinkedInApiClient client; 
public static final String LINKEDIN_PREF = "GamePrefs"; 

@SuppressLint({ "NewApi", "NewApi", "NewApi" }) 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.linkedin); 

    if (android.os.Build.VERSION.SDK_INT > 9) { 
     StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
     StrictMode.setThreadPolicy(policy); 
    } 

    oAuthService = LinkedInOAuthServiceFactory.getInstance().createLinkedInOAuthService(Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET, Constants.SCOPE_PARAMS); 
    System.out.println("oAuthService : " + oAuthService); 

    factory = LinkedInApiClientFactory.newInstance(Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET); 

    liToken = oAuthService.getOAuthRequestToken(Constants.OAUTH_CALLBACK_URL); 
    System.out.println("onCreate:linktoURL : " + liToken.getAuthorizationUrl()); 
    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(liToken.getAuthorizationUrl())); 
    startActivity(i); 

} 

@Override 
protected void onNewIntent(Intent intent) { 
    super.onNewIntent(intent); 

    try { 
     linkedInImport(intent); 
    } catch (NullPointerException e) { 
     e.printStackTrace(); 
    } 
} 

private void linkedInImport(Intent intent) { 
    String verifier = intent.getData().getQueryParameter("oauth_verifier"); 
    System.out.println("liToken " + liToken); 
    System.out.println("verifier " + verifier); 

    LinkedInAccessToken accessToken = oAuthService.getOAuthAccessToken(liToken, verifier); 
    //SharedPreferences settings = getSharedPreferences(LINKEDIN_PREF, MODE_PRIVATE); 
    // final Editor edit = settings.edit(); 
    // edit.putString(OAuth.OAUTH_TOKEN, accessToken.getToken()); 
    // edit.putString(OAuth.OAUTH_TOKEN_SECRET, 
    // accessToken.getTokenSecret()); 
    // edit.putString("linkedin_login", "valid"); 
    // edit.commit(); 

    client = factory.createLinkedInApiClient(accessToken); 

    // client.postNetworkUpdate("LinkedIn Android app test"); 

    Person profile = client.getProfileForCurrentUser(EnumSet.of(ProfileField.ID, ProfileField.FIRST_NAME, ProfileField.LAST_NAME, ProfileField.HEADLINE)); 

    System.out.println("First Name :: " + profile.getFirstName()); 
    System.out.println("Last Name :: " + profile.getLastName()); 
    System.out.println("Head Line :: " + profile.getHeadline()); 

    OAuthConsumer consumer = new CommonsHttpOAuthConsumer(Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET); 
    consumer.setTokenWithSecret(accessToken.getToken(), accessToken.getTokenSecret()); 

    DefaultHttpClient httpclient = new DefaultHttpClient(); 
    HttpPost post = new HttpPost("https://api.linkedin.com/v1/people/~/shares"); 
    try { 
     consumer.sign(post); 
     post.setHeader("content-type", "text/XML"); 
     String myEntity = "<share><comment>This is a test</comment><visibility><code>anyone</code></visibility></share>"; 
     post.setEntity(new StringEntity(myEntity)); 
     org.apache.http.HttpResponse response = httpclient.execute(post); 
     // Get the response 
     BufferedReader rd = new BufferedReader 
      (new InputStreamReader(response.getEntity().getContent())); 
     StringBuffer strBfr = new StringBuffer(); 
     String line = ""; 
     while ((line = rd.readLine()) != null) { 

      strBfr.append(line); 
     } 
     System.out.println("Response is : "+strBfr.toString()); 
     Toast.makeText(ShareInLinkedIn.this, strBfr.toString(), Toast.LENGTH_LONG).show(); 
    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 


} 

@Override 
public void onClick(View v) { 
    // TODO Auto-generated method stub 

} 

}

Constants.java

public class Constants { 

public static final String CONSUMER_KEY = "YOUR_CONSUMER_KEY"; 
public static final String CONSUMER_SECRET = "YOUR_CONSUMER_SECRET_KEY"; 
public static final String OAUTH_CALLBACK_SCHEME = "x-oauthflow-linkedin"; 
public static final String OAUTH_CALLBACK_HOST = "litestcalback"; 
public static final String OAUTH_CALLBACK_URL = OAUTH_CALLBACK_SCHEME + "://" + OAUTH_CALLBACK_HOST; 
public static final String SCOPE_PARAMS = "rw_nus+r_basicprofile"; 

}

AndroidManifiest.xml файл

 <activity 
     android:name="com.linkedin.ShareInLinkedIn" 
     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="litestcalback" 
       android:scheme="x-oauthflow-linkedin" /> 
     </intent-filter> 
    </activity> 
+0

Yes..But onNewIntent не вызывается, когда я с помощью вкладки .. –

+0

просто сделать новый андроид проект и сделайте это так и повторите это еще раз. –

+0

вы указали код, как показано выше, самый явный файл –