How to send data between one application to other application in android?

前端 未结 6 1091
再見小時候
再見小時候 2020-12-11 18:00

i\'ve tried to sending data between App1 to App2 via Intent in Android

i used this code but i couldn\'t resolve my problem.

<
6条回答
  •  清歌不尽
    2020-12-11 18:18

    Final code:

    App 1 :

            Intent intent = new Intent();
            intent.setClassName("com.appstore", "com.appstore.MyBroadcastReceiver");
            intent.setAction("com.appstore.MyBroadcastReceiver");
            intent.putExtra("KeyName","code1id");
            sendBroadcast(intent);
    

    App 2:

    Reciver:
    public class MyBroadcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            Toast.makeText(context, "Data Received from External App", Toast.LENGTH_SHORT).show();
    
        }
    }
    

    Manifest :

            
                
                    
                
            
    

    MainActivity :

      MyBroadcastReceiver mReceiver = new MyBroadcastReceiver();
            registerReceiver(mReceiver,
                    new IntentFilter("first_app_packagename"));
    

提交回复
热议问题