Android Share App Data (ACTION_SEND)含代碼

    Android Share App Data (ACTION_SEND)

    Android使用 ACTION_SEND 事件來發(fā)送數(shù)據(jù),其屬于 android.content.Intent 類,可以將數(shù)據(jù)從一個活動發(fā)送到另一個活動以及從當前活動發(fā)送到應用程序外部。愛掏網(wǎng) - it200.comIntent類需要指定要共享的數(shù)據(jù)及其類型。愛掏網(wǎng) - it200.com

    通常情況下,ACTION_SEND操作會發(fā)送內(nèi)置瀏覽器應用程序的URL。愛掏網(wǎng) - it200.com在共享數(shù)據(jù)時,Intent調(diào)用createChooser()方法,該方法接收Intent對象并指定選擇器對話框的標題。愛掏網(wǎng) - it200.com Intent.createChooser()方法用于顯示選擇器。愛掏網(wǎng) - it200.com

    ACTION_SEND示例

    在此示例中,我們將共享純文本,即瀏覽器的URL鏈接。愛掏網(wǎng) - it200.com

    activity_main.xml

    文件:activity_main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.example.test.shareapp.MainActivity">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!"
            android:id="@+id/textView" />
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Share App"
            android:id="@+id/button"
            android:layout_marginBottom="95dp"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true" />
    
    </RelativeLayout>
    

    Activity類

    文件:MainActivity.java

    package com.example.test.shareapp;
    
    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    
    public class MainActivity extends AppCompatActivity {
    Button sharebutton;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            sharebutton=(Button)findViewById(R.id.button);
            sharebutton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent shareIntent =   new Intent(android.content.Intent.ACTION_SEND);
                    shareIntent.setType("text/plain");
                    shareIntent.putExtra(Intent.EXTRA_SUBJECT,"Insert Subject here");
                    String app_url = " https://play.google.com/store/apps/details?id=my.example.javatpoint";
                    shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,app_url);
                    startActivity(Intent.createChooser(shareIntent, "Share via"));
                }
            });
        }
    }
    

    輸出

    聲明:所有內(nèi)容來自互聯(lián)網(wǎng)搜索結(jié)果,不保證100%準確性,僅供參考。如若本站內(nèi)容侵犯了原著者的合法權益,可聯(lián)系我們進行處理。
    發(fā)表評論
    更多 網(wǎng)友評論0 條評論)
    暫無評論

    返回頂部

    主站蜘蛛池模板: 日本一区二区视频| 狠狠色婷婷久久一区二区| 久久精品岛国av一区二区无码| 一区二区中文字幕| 国产在线观看一区精品| 怡红院一区二区在线观看| 亚洲一区二区三区免费在线观看 | 色综合视频一区中文字幕| 中文字幕精品亚洲无线码一区| 国产人妖视频一区在线观看| 中文字幕乱码人妻一区二区三区 | 国产在线视频一区二区三区| 亚欧在线精品免费观看一区| 日韩精品中文字幕无码一区| 国产成人一区二区三区视频免费 | 无码av人妻一区二区三区四区| 精品一区二区三区中文字幕| 国产美女视频一区| 久久毛片免费看一区二区三区| 国产MD视频一区二区三区| 国产产一区二区三区久久毛片国语| 午夜福利无码一区二区| 国产一区二区久久久| 亚洲日韩中文字幕一区| 交换国产精品视频一区| 无码视频免费一区二三区| 国产未成女一区二区三区| 在线|一区二区三区| 国产在线精品一区二区| 国产一区二区三区内射高清| 国产一区二区三区内射高清| 琪琪see色原网一区二区| aⅴ一区二区三区无卡无码| 中文字幕一区二区三区免费视频| 国产一区二区视频在线播放| 香蕉免费一区二区三区| 国产一区二区成人| 国产一区二区精品久久岳√ | 国产一区二区三区播放心情潘金莲| 91精品福利一区二区| 在线观看日韩一区|