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 com.example.android.supportv7.R;
     20 
     21 import android.content.Intent;
     22 import android.support.v4.view.MenuItemCompat;
     23 import android.support.v7.app.AppCompatActivity;
     24 import android.support.v7.widget.ShareActionProvider;
     25 import android.view.Menu;
     26 import android.view.View;
     27 
     28 /**
     29  * This activity demonstrates how to use {@link ShareActionProvider} with the Action Bar.
     30  */
     31 public class ActionBarShareActionProvider extends AppCompatActivity {
     32 
     33     @Override
     34     public boolean onCreateOptionsMenu(Menu menu) {
     35         getMenuInflater().inflate(R.menu.action_bar_share_action_provider, menu);
     36         return true;
     37     }
     38 
     39     @Override
     40     protected boolean onPrepareOptionsPanel(View view, Menu menu) {
     41         final ShareActionProvider sap = (ShareActionProvider) MenuItemCompat.getActionProvider(
     42                 menu.findItem(R.id.menu_item_share_provider_action_bar));
     43 
     44         final Intent shareIntent = new Intent(Intent.ACTION_SEND);
     45         shareIntent.setType("text/plain");
     46         shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello!");
     47 
     48         sap.setShareIntent(shareIntent);
     49 
     50         return true;
     51     }
     52 }
     53