How to show App icon in ACTION_SEND intent - android - java

I want the app icon to be shown when sharing my app inside my app. When clicking the Share the App button in my App. It works but instead of my icon, it shows some other icon.
It shows like Below
Here's the code I used:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, " Knowledge");
String shareMessage= "\n Download now for free !\n\n";
shareMessage = shareMessage + "https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID +"\n\n";
shareIntent.putExtra(Intent.EXTRA_TEXT, shareMessage);
context.startActivity(Intent.createChooser(shareIntent, "choose one"));
How can I set my icon in here? Please help me with some solution

Congratulations guys, you waited for this :)
In some cases you need to add several Intent filters:
<activity
android:name=".activity.FeedActivity"
android:exported="true"
android:label="#string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
And be sure you add the android:exported="true" tag otherwise you app won't appear in other share intents.

Related

Strange app icon duplication in pinned shortcut (Android O)

I'm creating a pinned shortcut of my app launcher icon for Android O device (either emulator or physical device) and found strange behaviour. My code looks like this:
#TargetApi(Build.VERSION_CODES.O)
private void createPinnedShortcut(Context context) {
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
if (shortcutManager != null) {
if (shortcutManager.isRequestPinShortcutSupported()) {
Intent intent= MainActivity.getLaunchIntent(this);
intent.setAction(Intent.ACTION_VIEW);
ShortcutInfo shortcut = new ShortcutInfo.Builder(context, "my_shortcut_id")
.setShortLabel(context.getString(R.string.my_app_description))
.setLongLabel(context.getString(R.string.my_app_long_description))
.setIcon(Icon.createWithResource(context, R.mipmap.my_app_icon))
.setIntent(intent)
.build();
shortcutManager.requestPinShortcut(shortcut, null);
} else
Toast.makeText(context, "Pinned shortcuts are not supported!", Toast.LENGTH_SHORT).show();
}
}
Everything works, but the launcher icon on the home screen is duplicated:
There is a normal icon, but on right lower corner it placed yet another copy of the icon (about 30-40% smaller).
My icon resources are in res/mipmap-*dpi* folders
Any hints, clues?
Update
Answering to comments:
1) AndroidManifest under ./build/manifests/debug looks like:
<activity
android:name="ru.ivanovpv.cellboxkeeper.android.MainActivity"
android:exported="true"
android:label="#string/cellboxkeeper"
android:theme="#style/DefaultActivityTheme.Light"
android:windowSoftInputMode="adjustResize" >
<layout
android:defaultHeight="800dp"
android:defaultWidth="480dp"
android:gravity="top|end"
android:minHeight="320dp"
android:minWidth="240dp" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter> <!-- handle cbx files -->
<intent-filter
android:icon="#mipmap/cellboxkeeper"
android:label="#string/cellboxkeeper"
android:logo="#mipmap/cellboxkeeper" >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.cbx"
android:scheme="content" />
</intent-filter>
<!-- receive files from android share intent -->
<intent-filter
android:icon="#mipmap/cellboxkeeper"
android:label="#string/addToCellboxKeeper" >
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
<data android:mimeType="*/*" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
2) There's not any folder like: mipmap-*-v26. Here's screenshot of folders in real apk. All icons in folders are normal (w/o duplication).
Any other versions?
I found solution, key is attribute android:logo:
<intent-filter
android:icon="#mipmap/cellboxkeeper"
android:label="#string/cellboxkeeper"
android:logo="#mipmap/cellboxkeeper" >
<action android:name="android.intent.action.VIEW" />
Deleting line with android:logo fixes duplication issue.
Hope, someone and sometimes will use and understands what's goin on

Adding 3rd party application into Settings.apk

Recently I'm building a AOSP ROM from source. What I wanted to do is, add a 3rd party application into Settings app and It should be launched only from Settings and it should be invisible from Launcher.
Here's what I did, It fails everytime.
Removed these lines from apps AndroidManifest.xml
android:name="android.intent.category.LAUNCHER" />
and added below lines in SettingsActivity.java from Settings app.
if (KA_FRAGMENT.equals(fragmentName)) {
Intent kaIntent = new Intent();
kaIntent.setClassName("com.cyborg.manager", "com.cyborg.manager.activities.MainActivity");
startActivity(kaIntent);
finish();
return null;
}
Also added below lines in AndroidManifest.xml of Settings
<activity android:name="Settings$KActivity"
android:label="#string/hit_perform"
android:icon="#drawable/hit_performance_icon"
android:taskAffinity="" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
<intent-filter android:priority="1">
<action android:name="com.android.settings.action.SETTINGS" />
</intent-filter>
<meta-data android:name="com.android.settings.category"
android:value="com.android.settings.category.urom" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.ka" />
</activity>
Although, it works fine when 3rd party app is visible in launcher
If you want to play with custom ROM I'd recommend getting familiar with Android fundamentals first.
What makes you activity shown by launcher is this <intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
especially these two lines:
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
so remove them and you are done.

Android app chooser doesn't show while opening website

I have created a browser application with below code,
AndroidManifest.xml
<activity
android:name=".CustomBrowserActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" android:host="www.google.com" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
Now I have another application which tries to open google home page http://www.google.com
Intent intentToOpen = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
Intent chooserIntent = Intent.createChooser(intentToOpen, "Load http://www.google.com with: ");
Now, whenever above code is executed, default browser is opened, rather than my custom browser.
Any help would be appreciated.

Get mail intent from whatsapp

I am trying to receive the sending whatsapp intent when sharing the conversation via email.I can't make my application appear in the possible applications to share.I need information on how to properly configure my androidmanifest and receive the attachment * .txt.Thanks and I hope I have expressed myself well.
You need an <intent-filter> in your activity that will be handling the email:
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<action android:name="android.intent.action.SENDTO"/>
<data android:scheme="mailto"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
<intent-filter android:label="#string/app_name">
<action android:name="android.intent.action.SEND"/>
<data android:mimeType="*/*"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter android:label="#string/app_name">
<action android:name="android.intent.action.SEND_MULTIPLE"/>
<data android:mimeType="*/*"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
This is what the email app uses.
Source: android intent-filter to listen for sent email addresses?
Your application doesn't appear in the chooser because Whatsapp has whitelisted only some packages for the email applications.
For more information, see this answer

Android add my app to "Share" button in gallery

I succeed to add my app in the "share" button in the Android gallery, so if I click on it, my app will start. Can I choose which activity of my app to start?
Now it starts the "main" one. Here's my code in the main class:
.....
Intent intent = getIntent();
Bundle extras = intent.getExtras();
String action = intent.getAction();
// if this is from the share menu
if (Intent.ACTION_SEND.equals(action)) {
if (extras.containsKey(Intent.EXTRA_STREAM)) {
// Get resource path
}
}
And the manifest:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
In reality I succeed in opening a new activity immediately after the "main" starts but I'll prefer to directly open the right one.
Thanks
Put your intent filter under activity you want to start into your manifest
<activity android:name=".Theme"
android:label="MAIN">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Theme"
android:label="ActiVITY2">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
If you had two activities in your manifest file, say Main and MediaShare then it would look something like this:
<activity android:name="Main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="MediaShare" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
The android.intent.action.SEND action and android:mimeType="image/*" data should go with the activity you want to start when you share an image.
See the page on Receiving Content from Other Apps for more details.

Categories

Resources