How to send data to another app which is not started

后端 未结 1 1486
有刺的猬
有刺的猬 2021-01-26 06:47

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

相关标签:
1条回答
  • 2021-01-26 07:06

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

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

    In the sending app:

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

    In the receiving app:

    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>
    
    0 讨论(0)
提交回复
热议问题