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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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>