简体   繁体   English

读取值并通过Android中的其他应用程序共享它

[英]Read the value and Share it via different apps in android

i have a problem with sharing data through Sharing Intent. 我在通过共享意图共享数据时遇到问题。 Here's is code of sharing the data via different app. 这是通过其他应用程序共享数据的代码。

  btnshare.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {


            Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
            sharingIntent.setType("text/plain");
            String shareBody = "The Langitude: "+longi+"The Latitude:"+lati;
            sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,value);
            sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
            startActivity(Intent.createChooser(sharingIntent, "Share via"));


        }
    });

it just a button which is work for sharing . 它只是一个可以共享的按钮。 but now the prolem is i want share some value in that case (lati, longi which i've got from textview. how can i pass the value to the message body of the share action. 但是现在的问题是,在这种情况下,我想分享一些价值(我从textview中获取的经度,经度。我该如何将该值传递给共享动作的消息主体。

for information here's the origin of '[lati' and 'longi']value they belong from different method but they are in same class. 为了提供信息,以下是'[lati'和'longi']值的来源,它们属于不同的方法,但它们在同一类中。

private void getLocation() {

    locationListener = new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            Log.d("Location:", location.toString());
            double lati =location.getLatitude();
            double longii=location.getLongitude();
            double alt=location.getAltitude();

            txt_lati.setText("" +lati);
            txt_longi.setText(""+longii);
            return;

        }

here's the method where lati and longi belongs. 这是lati和longi所属的方法。 now my question is how can i share the latitude(lati) and longitude(longi) values via sharing prompt? 现在我的问题是如何通过共享提示共享纬度(lati)和经度(longi)值? i mean how can i share that specific two data? 我的意思是我该如何共享这两个数据? fyi if i'm going to share this way the value isn't comming .something like v7.appcompact that kind of text filled up in message body. 仅供参考,如果我要以这种方式分享,那么值就不会来了。像v7.app之类的东西会压缩在邮件正文中填充的那种文本。

you need to make your first app activity intent as action intent 您需要将您的第一个应用程序活动意图作为行动意图

like 喜欢

<activity
    android:name=".FeedbackActivity" >  
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
        <action android:name="com.example.foo.bar.YOUR_ACTION" />
    </intent-filter>
</activity>

and you can call it from another application 您可以从另一个应用程序调用它

String CUSTOM_ACTION = "com.example.foo.bar.YOUR_ACTION";   
Intent i = new Intent();
i.setAction(CUSTOM_ACTION);    
startActivity(i);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM