Send the data to one app to another app using intent and broadcast - Part 2

Previous post I explain about the sharing the data using broadcast. This post about to share the data using the intents.

By using Intent

In First Application

Intent intent = new Intent();
intent.setClassName("com.sample.app", "com.sample.app.MainActivity");
intent.putExtra("EXTRA_ORDERID", "#4FGT784");
intent.putExtra("EXTRA_ORDERNOTES", "No warranty for this product");
intent.putExtra("EXTRA_ORDERAMOUNT", "270");


PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
boolean isIntentSafe = activities.size() > 0;

if (isIntentSafe) {
startActivity(intent);
} else {
Toast.makeText(MainActivity.this, "Application not installed", Toast.LENGTH_LONG).show();
}

In Second Application

Bundle vals = getIntent().getExtras();
if (vals != null) {
String orderId = vals.getString("EXTRA_ORDERID", "");
String orderNotes = vals.getString("EXTRA_ORDERNOTES", "No notes");
String orderAmount = vals.getString("EXTRA_ORDERAMOUNT", "0");

StringBuilder builder = new StringBuilder();
builder.append("order_Id " + orderId + "/n");
builder.append("order_notes " + orderNotes + "/n");
builder.append("order_amount " + orderNotes);
txt_data.setText(builder.toString());
}


I Hope this will be very easier and good. 

Comments

Popular posts from this blog

Clear the app data programmatically in android

Speed up gradle build in Android Studio.

Proguard usage in Android