我怎么能发送数据(文本)到其他应用程序(如消息) [英] How could I Send Data(Text) to other apps(like messages)

查看:129
本文介绍了我怎么能发送数据(文本)到其他应用程序(如消息)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能作出这样的输入字符串和preSS一个键后,该字符串存储在手机中的程序(共享preferences),然后如果我打开程序发送SMS(消息) 3秒钟后,在消息的EditText写之前存储的字符串。

How could I make a program that after entering a string and press a key, the string is stored in the phone (SharedPreferences), and then if I open the program to Send Sms(messages), 3 seconds later write in the Message EditText the string stored before.

到目前为止,我已经做到了这一点:

so far I've done this:

@Override 
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);  

  EditText stringinput = (EditText) findViewById(R.id.string);
  Button bu = (Button) findViewById(R.id.button1);
  stringinput.setImeOptions(EditorInfo.IME_ACTION_DONE); 
  bu.setOnClickListener(this);
}

@Override  
public void onClick(View v) {  
  EditText stringinput = (EditText) findViewById(R.id.string);
  String name = stringinput.getText().toString();   
  if(v.getId()==(R.id.string)){  
  SavePreferences("STRING",name);  
  }
}  

private void SavePreferences(String key, String value){  
  SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);  
  SharedPreferences.Editor editor = sharedPreferences.edit();  
  editor.putString(key, value);  
  editor.commit();  
 }  

private void LoadPreference(){         
      SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);           
      String strSavedMem1 = sharedPreferences.getString("STRING", ""); 
     /******************** stringoutput.append(strSavedMem1);*******************/
      }
}

现在好了,我不知道如何前进--->我认为最难的工作是在这个函数加载preferences(); ,也许我应该建立一个隐含意图

Ok Now I do not Know how to move forward---> I think that the hardest work is in this function LoadPreferences(); , Perhaps I should Build an Implicit Intent

Intent SEND = new Intent(Intent.ACTION_SEND);

我不知道,帮我普莱舍

I don't Know , help me plese

推荐答案

如果您正试图将消息发送到其他应用程序在Android的运行,或者离开的消息对他们来说,我想看看在Android运行在单独的进程服务服务教程在这里: http://www.vogella.com/articles/AndroidServices/article.html
您可以让服务跟踪字符串传递给它,并有其他应用程序绑定到服务,让他们回来。

If you are trying to send messages to other applications running in android, or to leave messages for them, I would check out running services in seperate processes in the android service tutorial here: http://www.vogella.com/articles/AndroidServices/article.html You can have the service keep track of strings you pass it, and have other applications bind to the service to get them back.

否则,如果你只是想保存字符串到一个文件,一个属性文件会做就好了。如果其他应用程序需要能够读取该文件,将其保存到外部存储器。那里有一个很好的教程,这是如何在这里工作的主要的Andr​​oid网站: HTTP: //developer.android.com/guide/topics/data/data-storage.html

Otherwise, if you just want to save strings to a file, a property file would do just fine. If other applications need to be able to read the file, save it to external storage. Theres a good tutorial for how this works on the main android site here: http://developer.android.com/guide/topics/data/data-storage.html

编辑:如果您使用的共享preferences共享应用程序之间的字符串死心塌地,另一个堆栈溢出的用户发布了tuturial就在这里:<一href=\"http://stackoverflow.com/questions/11025234/how-can-i-share-a-shared$p$pferences-file-across-two-different-android-apps\">How我可以在两个不同的Andr​​oid应用程序共享共享preferences文件?

If you are dead set on using shared preferences to share strings between applications, another stack overflow user posted a tuturial on it here: How can I share a SharedPreferences file across two different android apps?

这篇关于我怎么能发送数据(文本)到其他应用程序(如消息)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆