Home | History | Annotate | Download | only in app
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.example.android.supportv7.app;
     18 
     19 import android.content.Intent;
     20 import android.view.Menu;
     21 import android.view.View;
     22 
     23 import androidx.appcompat.app.AppCompatActivity;
     24 import androidx.appcompat.widget.ShareActionProvider;
     25 import androidx.core.view.MenuItemCompat;
     26 
     27 import com.example.android.supportv7.R;
     28 
     29 /**
     30  * This activity demonstrates how to use {@link ShareActionProvider} with the Action Bar.
     31  */
     32 public class ActionBarShareActionProvider extends AppCompatActivity {
     33 
     34     @Override
     35     public boolean onCreateOptionsMenu(Menu menu) {
     36         getMenuInflater().inflate(R.menu.action_bar_share_action_provider, menu);
     37         return true;
     38     }
     39 
     40     @Override
     41     protected boolean onPrepareOptionsPanel(View view, Menu menu) {
     42         final ShareActionProvider sap = (ShareActionProvider) MenuItemCompat.getActionProvider(
     43                 menu.findItem(R.id.menu_item_share_provider_action_bar));
     44 
     45         final Intent shareIntent = new Intent(Intent.ACTION_SEND);
     46         shareIntent.setType("text/plain");
     47         shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello!");
     48 
     49         sap.setShareIntent(shareIntent);
     50 
     51         return true;
     52     }
     53 }
     54