'using startActivity() to open a share dialog, but content was less than what i see in log
when using startActivity() to open a share dialog, but content was less than what i see in log. Can anyone explain this phenomenon?
private static final String TAG = "MainActivity";
private void testShare() {
List<Intent> intentList = new ArrayList<>();
PackageManager pm = getPackageManager();//get PackageManager
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "title");
shareIntent.putExtra(Intent.EXTRA_TEXT, "text");
List<ResolveInfo> resInfo = pm.queryIntentActivities(shareIntent, 0);
Log.d(TAG, "testShare: resInfo.size = "+resInfo.size());
for (int i = 0; i < resInfo.size(); i++) {
//I will screen some apps here in the future
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "title");
intent.putExtra(Intent.EXTRA_TEXT, "text");
ResolveInfo ri = resInfo.get(i);//get intent resolveInfo data
String packageName = ri.activityInfo.packageName;
intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));//finish init
intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
}
//use createChooser to pack a share intent list
Intent chooserIntent = Intent.createChooser(intentList.remove(0), "Share to...");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentList.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
}
this is what the log shows: the log shows here can see 28 apps
and this is the effect of running: is the effect of running but here just only show 5 apps
by the way, i'm using android12 RedmiK40, so i have already add queries Tag in AndroidManifest.xml
<queries>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="text/plain"/>
</intent>
</queries>
Can anyone tell me what I did wrong?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|