Android Share App Data (ACTION_SEND)含代碼

Android Share App Data (ACTION_SEND)

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

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

ACTION_SEND示例

在此示例中,我們將共享純文本,即瀏覽器的URL鏈接。愛掏網 - 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"));
            }
        });
    }
}

輸出

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

返回頂部

主站蜘蛛池模板: 亚洲国产一成人久久精品| 国产a级午夜毛片| 久久精品这里有| 中文字幕第一页在线视频| 亚洲日本久久一区二区va| 最近中文字幕免费4| 大伊香蕉在线观看视频wap| 向日葵app看片视频| j8又粗又大又长又爽又硬男男| 污污动漫在线观看| 国产精品久久久久久无毒不卡| 久久人人爽人人爽人人片av高请| 成人免费在线看片| 日本三级香港三级人妇99视| 国产亚洲精久久久久久无码| 久久超碰97人人做人人爱| 色综合综合色综合色综合| 欧美日韩亚洲另类| 国产精品成人va| 亚洲日韩一区二区三区| 91秦先生在线| 欧美精品xxxxbbbb| 国产成人午夜福利在线播放| 久久精品青青大伊人av| 美女视频内衣脱空一净二净| 在线观看噜噜噜私人影院| 亚洲熟妇无码爱v在线观看| 99热都是精品久久久久久| 欧美videosdesexo肥婆| 四虎影视在线观看永久地址| 两个人一上一下剧烈运动| 精品国产福利在线观看| 国产裸拍裸体视频在线观看| 久久人人爽人人爽人人片dvd | 一本一本久久a久久精品综合麻豆| 美日韩一区二区三区| 在线jyzzjyzz免费视频| 久久精品国产99国产精品 | 免费国产成人午夜在线观看| 一区二区三区影院| 日韩精品无码久久一区二区三 |