如何将数据发送到另一个应用程序,它没有启动发送到、如何将、应用程序、数据

2023-09-03 22:05:22 作者:旧城旧伤

我已经做了一个应用程序,经过2年的该许可证过期。我想提出另外一个应用程序,我想使用的第一个应用的牌照续期。我会提供给用户,他将在第二个应用程序进入到更新的第一个应用程序的关键。为此,我想知道如何发送我的第一个应用程序的关键?

I have made a app for which licence expires after 2 years. And I am making another app which I want to use for renewal of the licence of the first app. I will provide user with a key which he will enter in second app to renew the first app. For this I want to know How do I send my first app the key?

推荐答案

您可以使用BroadcastReceivers应用程序之间的通信。 在这里查看文档:

You can communicate between apps using BroadcastReceivers. Check the documentation here:

http://developer.android.com/reference/android/content/ BroadcastReceiver.html

在发送应用程序:

public void broadcastIntent(View view)
{
   Intent intent = new Intent();
   intent.setAction("SOME_ACTION");
   intent.putExtras("key",key);
   sendBroadcast(intent);
}

在接收应用程序:

public class MyReceiver extends BroadcastReceiver {

   @Override
   public void onReceive(Context context, Intent intent) {
      Toast.makeText(context, "Intent Detected.", Toast.LENGTH_LONG).show();
      String key=intent.getStringExtra("key");
      // do something with the key
   }

}

在接收应用程序的清单文件,在<应用> 标签:

In the manifest file of the receiving app, under <application> tag:

<receiver android:name="MyReceiver">
      <intent-filter>
         <action android:name="SOME_ACTION"> <!-- Here you can use custom actions as well, research a little -->
      </action>
      </intent-filter>
   </receiver>