Guest User

Untitled

a guest
Apr 5th, 2014
163
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
  2. shareIntent.setType("text/plain");
  3. shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Content to share");
  4. PackageManager pm = contexto.getPackageManager();
  5. List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
  6. for (final ResolveInfo app : activityList) {
  7. if ("com.twitter.android.PostActivity".equals(app.activityInfo.name)) {
  8. final ActivityInfo activity = app.activityInfo;
  9. final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
  10. shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
  11. shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
  12. shareIntent.setComponent(name);
  13. contexto.startActivity(shareIntent);
  14. break;
  15. }
  16. }
  17.  
  18. android.content.ActivityNotFoundException: Unable to find explicit activity class {com.twitter.android/com.twitter.android.PostActivity}; have you declared this activity in your AndroidManifest.xml?
  19.  
  20. Intent intent = null;
  21. try {
  22. // get the Twitter app if possible
  23. this.getPackageManager().getPackageInfo("com.twitter.android", 0);
  24. intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=USERID"));
  25. intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  26. } catch (Exception e) {
  27. // no Twitter app, revert to browser
  28. intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/USERID_OR_PROFILENAME"));
  29. }
  30. this.startActivity(intent);
  31.  
  32. Intent tweetIntent = new Intent(Intent.ACTION_SEND);
  33. tweetIntent.putExtra(Intent.EXTRA_TEXT, "This is a Test.");
  34. tweetIntent.setType("text/plain");
  35.  
  36. PackageManager packManager = getPackageManager();
  37. List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(tweetIntent, PackageManager.MATCH_DEFAULT_ONLY);
  38.  
  39. boolean resolved = false;
  40. for(ResolveInfo resolveInfo: resolvedInfoList){
  41. if(resolveInfo.activityInfo.packageName.startsWith("com.twitter.android")){
  42. tweetIntent.setClassName(
  43. resolveInfo.activityInfo.packageName,
  44. resolveInfo.activityInfo.name );
  45. resolved = true;
  46. break;
  47. }
  48. }
  49. if(resolved){
  50. startActivity(tweetIntent);
  51. }else{
  52. Toast.makeText(this, "Twitter app isn't found", Toast.LENGTH_LONG).show();
  53. }
RAW Paste Data