nicolausYes
nicolausYes

Reputation: 653

Open invisible activity on share action (ACTION_SEND)

There are a lot of similar questions on StackOverfow but they don't solve my problem.

The task is to process in Service intents sent with default share mechanism (ACTION_SEND) from different applications.
But as far as ACTION_SEND is an activity action we have to pick up intent in activity and broadcast it to service. And it will be perfect if this activity will be invisible to the user.

I've researched a lot and have tried many solutions already.

  1. First step of making activity invisible belongs to activity style.

    I've tried this values.

    android:theme="@android:style/Theme.Translucent.NoTitleBar"

    android:theme="@android:style/Theme.Translucent"

    android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"

    Also i"ve tried to create a custom theme.

    <style name="Theme.Transparent" parent="android:Theme">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:backgroundDimEnabled">true</item>
    </style>
    

    How the activity in AndroidManifest.xml looks like.

    <activity
        android:name="xxx.xxx.activities.HandleShareIntentActivity"
        android:theme="@style/Theme.Transparent"
        android:noHistory="true"
        android:excludeFromRecents="true"
        android:label="@string/title_activity_handle_share_intent">
       <intent-filter>
           <action android:name="com.google.android.gm.action.AUTO_SEND"/>
           <action android:name="android.intent.action.SEND"/>
           <action android:name="android.intent.action.SEND_MULTIPLE"/>
           <category android:name="android.intent.category.DEFAULT"/>
           <category android:name="com.google.android.voicesearch.SELF_NOTE"/>
           <data android:mimeType="*/*"/>
       </intent-filter>
    </activity>
    
  2. Activity code. No setContentView(). finish() in onCreate().

    public class HandleShareIntentActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            startService(new Intent(this, xxxService.class).putExtra(
            Constants.ACTION_SHARE_KEY, getIntent()));
    
            finish();
        }  
     }
    

On Nexus 5, android 4.4.4 I do have black screen blink while handling any share event.
Any solutions?

Upvotes: 4

Views: 1856

Answers (2)

no one special
no one special

Reputation: 1764

I Just did this, and it helped in my case:

<activity
    android:name=".SensorBoardActivity"
    android:theme="@android:style/Theme.NoDisplay"
    android:excludeFromRecents="true"
    android:noHistory="true">

I see you already have finish(); but just for others it is important to execute it just before leaving the onCreate().

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1007296

I've tried this values.

Use Theme.NoDisplay.

Upvotes: 3

Related Questions