2014-08-30 49 views
0

我有代碼爲ACTION_SEND意圖過濾特定的應用程序。 但我無法設置Gmail和郵件EXTRA_EMAIL。PutExtra EXTRA_EMAIL如何爲Action_send?

我試試這個:

String packageName = ri.activityInfo.packageName; 
         if(packageName.contains("email")) 
         { 
         emailIntent.setPackage(packageName); 
         } 
         else if(packageName.contains("android.gm") || packageName.contains("mail")) 
         { 
          Intent intent = new Intent(); 
          intent.setComponent(new ComponentName(packageName, ri.activityInfo.name)); 
          intent.setAction(Intent.ACTION_SEND); 
          intent.setType("text/plain"); 
          if(packageName.contains("android.gm")) { 
          intent.putExtra(Intent.EXTRA_SUBJECT, resources.getString(R.string.share_email_subject)); 
          intent.putExtra(Intent.EXTRA_EMAIL,"[email protected]"); 

回答

0

你需要檢查這種方式。

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); 
    shareIntent.setType("text/plain"); 
    shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "urSubject"); 
    shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "ExtraText"); 

    PackageManager pm = v.getContext().getPackageManager(); 
    List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0); 
    for (final ResolveInfo app : activityList) 
    { 
     if ((app.activityInfo.name).contains("gmail")) 
     { 
     final ActivityInfo activity = app.activityInfo; 
     final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name); 
     shareIntent.addCategory(Intent.CATEGORY_LAUNCHER); 
     shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 
     shareIntent.setComponent(name); 
     v.getContext().startActivity(shareIntent); 
     break; 
     } 
    } 
+0

你用什麼v?通過這種方式@PG_Android – programmer 2014-08-30 09:51:27

0
final Intent intent = new Intent(
          android.content.Intent.ACTION_SEND); 
        intent.setType("*/*"); 
        intent.putExtra(android.content.Intent.EXTRA_SUBJECT, 
          "subject name"); 


         intent.putExtra(android.content.Intent.EXTRA_STREAM, 
           Uri.fromFile(new File(file.toString()))); 


        final PackageManager pm = getPackageManager(); 
        final List<ResolveInfo> matches = pm.queryIntentActivities(
          intent, 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) 
         intent.setClassName(best.activityInfo.packageName, 
           best.activityInfo.name); 
        startActivity(intent); 
+0

你可以設置電子郵件? – programmer 2014-08-30 10:06:15

+0

我不能!!!!!!! – programmer 2014-08-30 10:06:45

1

的EXTRA_EMAIL額外要求字符串的數組。使用字符串數組構造函數

Intent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "[email protected]" });