2012-12-28 36 views
0

嗨在我的android phonegap應用程序我已經使用創建選擇器來從mobile.Its所有共享應用程序工作正常,但我需要調用facebook的單獨意圖。所以我需要Click事件的Facebook從對話框中。點擊事件的facebook在android中

這裏是我的代碼:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
    emailIntent.setType("text/plain"); 
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); 
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"www.google.com"); 

    this.ctx.startActivity(Intent.createChooser(emailIntent, "Share")); 

敬請指導me.Thanks提前。

回答

0

試試這個:

try { 
     Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
     String[] recipients = new String[]{"e-mail address"}; 
     emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients); 
     emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "E-mail subject"); 
     emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "E-mail text"); 
     emailIntent.setType("plain/text"); // This is incorrect MIME, but Gmail is one of the only apps that responds to it - this might need to be replaced with text/plain for Facebook 
     final PackageManager pm = getPackageManager(); 
     final List<ResolveInfo> matches = pm.queryIntentActivities(emailIntent, 0); 
     ResolveInfo best = null; 
     for (final ResolveInfo info : matches) 
      if (info.activityInfo.packageName.endsWith(".gm") || 
        info.activityInfo.name.toLowerCase().contains("gmail")) best = info; 
       if (best != null) 
        emailIntent.setClassName(best.activityInfo.packageName, best.activityInfo.name); 
       startActivity(emailIntent); 
    } catch (Exception e) { 
     Toast.makeText(this, "Application not found", Toast.LENGTH_SHORT).show(); 
    } 

你也可以嘗試uaual方式:

Intent intent = new Intent(Intent.ACTION_SEND); 
intent.setType("text/plain"); 
intent.putExtra(Intent.EXTRA_TEXT, "The status update text"); 
startActivity(Intent.createChooser(intent, "Dialog title text")); 
+0

@ ricintech..Thanks您reply.your代碼,我直接移動到email.But我需要得到所有共享應用程序的對話框,從那裏我需要點擊email.Please指導我。 – JavaH

+0

好的,你想要顯示一個具有所有應用程序名稱的項目。 –

+0

雅,如果我使用createchooser它會自動打開對話框的應用程序名稱作爲項目,它本身是sharing.But我需要在我自己的Facebook使用單獨的點擊事件。請引導我.. – JavaH