如何将数据(文本)发送到其他应用程序(如消息) [英] How could I Send Data(Text) to other apps(like messages)
问题描述
如何编写一个程序,输入一个字符串并按一个键后,该字符串存储在手机中(SharedPreferences),然后如果我打开程序发送短信(消息),3秒后写入消息编辑以前存储的字符串。
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);*******************/
}
}
Ok现在我不知道如何移动forward --->我认为最难的工作是在这个函数中LoadPreferences(); ,也许我应该建立隐含意图
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);
我不知道,帮助我plese
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.
否则,如果您只是想将字符串保存到一个文件,一个属性文件会做的很好。如果其他应用程序需要能够读取文件,请将其保存到外部存储器。这是一个很好的教程,这是如何在主要的Android网站在这里工作: 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
编辑:如果您在使用共享首选项时死机在应用程序之间共享字符串,另一个堆栈溢出用户在这里发布了一个琐事:如何在两个不同的Android应用程序之间共享一个SharedPreferences文件?
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屋!