因为我们可以在应用程序内将数据从一个 Activity 发送到另一个应用程序,也可以通过使用将数据从一个应用程序发送到另一个应用程序,Intent
我可以使用以下代码将数据从我的一个应用程序发送到另一个应用程序,
只需考虑有两个应用程序APP1
,APP2
并且我m 从APP1
to发送数据APP2
,反之亦然。
在APP1
包名中:(com.sush.myApp)
public class HomeActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
// to receive data from com.my.demo package and display it to TextView
TextView mText = (TextView)findViewById(R.id.textView1);
String name=getIntent().getStringExtra("User_Message");
mText.setText(name);
// to send data from com.sush.myApp package to com.my.demo package
Button btn1 =(Button)findViewById(R.id.button1);
btn1.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
try
{
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("com.my.demo");
i.putExtra("User_ID", "sush19");
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
}catch(Exception e)
{
e.printStackTrace();
Toast.makeText(v.getContext(), "App Not Found", Toast.LENGTH_LONG).show();
}
}
});
}
并从APP2
包名称:(com.my.demo)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// to receive data from com.sush.myApp package and display it to TextView
final TextView txt1 = (TextView)findViewById(R.id.Text1);
String name=getIntent().getStringExtra("User_ID");
txt1.setText(name);
// to send data from com.my.demo package to com.sush.myApp package
Button btnSending = (Button)findViewById(R.id.btnSend);
final EditText myMessage = (EditText)findViewById(R.id.txtMessage);
btnSending.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
if (myMessage.getText().toString().equals(""))
{
Toast.makeText(v.getContext(), "Enter your message", Toast.LENGTH_SHORT).show();
}
else
{
try
{
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("com.sush.myApp");
i.putExtra("User_Message", myMessage.getText().toString());
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
}catch(Exception e)
{
e.printStackTrace();
Toast.makeText(v.getContext(), "Error: "+e, Toast.LENGTH_LONG).show();
}
}
}
});
}
它的工作完美..
Now my problem is I want to do same operation i.e sending data from one app to another but my first app is in Java created using Eclipse and my second app is in ActionScript created using AIR for Android in Adobe Flash Professional CS6
有没有一种方法可以使用Intent
,PackageManager
以便Actionscript
我可以轻松地将数据从 AIR 应用程序发送到 Android 应用程序,如果是,那么任何人都可以给我一个例子
或者任何人都可以给我一个关于如何将数据从 Android 应用程序发送到 AIR 的例子对于Android App,反之亦然..
谢谢...