2013-11-27 2 views
4

내 앱에서 트위터를 열고 트위터가 열리면 사용자 이름 정보와 일부 텍스트 (메시지)가있는 직접 메시지 창이 표시되므로 앱의 사용자는 읽기만하면됩니다. 그가 원하는 경우 메시지를 수정하고 보내기를 누릅니다.안드로이드가 트위터 직접 메시지를 의도를 통해 보냅니다.

다음 코드는 이 짹짹을 작성하는 중입니다. 트위터 앱이 설치되어 있지 않으면 웹 브라우저에서 트위터를 열려고합니다. 누락 된 부분은 기본 Twitter 응용 프로그램에서 직접 메시지를 준비하는 것입니다.

try{ 
    Intent intent = new Intent(Intent.ACTION_SEND); 
    intent.putExtra(Intent.EXTRA_TEXT, "It's a Tweet!" + "#MyApp"); 
    intent.setType("text/plain"); 
    final PackageManager pm = getPackageManager(); 
    final List<?> activityList = pm.queryIntentActivities(intent, 0); 
    int len = activityList.size(); 
    for (int i = 0; i < len; i++) { 
     final ResolveInfo app = (ResolveInfo) activityList.get(i); 
     Log.i("APP",app.activityInfo.name); 
     if ("com.twitter.applib.PostActivity".equals(app.activityInfo.name)) { 
      final ActivityInfo activity=app.activityInfo; 
       final ComponentName x=new ComponentName(activity.applicationInfo.packageName, activity.name); 
       intent=new Intent(Intent.ACTION_SEND); 
       intent.addCategory(Intent.CATEGORY_LAUNCHER); 
       intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 
       intent.setComponent(x); 
       intent.putExtra(Intent.EXTRA_TEXT, "blah blah"); 
       startActivity(intent); 
       break; 
     } 
    } 
} catch(final ActivityNotFoundException e) { 
    Log.i("Twitter intent", "no twitter native", e); 
    String usernameWeb="https://twitter.com/direct_messages/create/"+user; 
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(usernameWeb))) 
} 

고마워요!

답변

2
try { 
     Intent openNewIntent = new Intent(); 
     String mPackage = "com.twitter.android"; 
     String mClass = ".DMActivity"; 
     openNewIntent.setComponent(new ComponentName(mPackage,mPackage+mClass)); 
     openNewIntent.putExtra("user_ids", new long[]{follower_uid}); 
     openNewIntent.putExtra("keyboard_open", true); 
     startActivity( openNewIntent); 
    } catch (Exception e) { 
     startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/direct_messages/create/" + screen_name))); 
     //e.printStackTrace(); 
    } 
+0

어디서 follower_uid를 가져야합니까? –

관련 문제