Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mysender;
- import android.content.ComponentName;
- import android.content.Intent;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- final Intent intent=new Intent();
- intent.setAction("com.mysender.Data");
- intent.putExtra("path", "/Download/income_tax_return.pdf");
- intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
- intent.setComponent(new ComponentName("com.example.app","com.example.app.MainActivity"));
- sendBroadcast(intent);
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.mysender">
- <application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- android:roundIcon="@mipmap/ic_launcher_round"
- android:supportsRtl="true"
- android:theme="@style/AppTheme">
- <activity android:name=".MainActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- </manifest>
- ackage com.example.app;
- import android.app.Activity;
- import android.content.Context;
- import android.content.Intent;
- import android.content.IntentFilter;
- import android.os.Bundle;
- import android.widget.Toast;
- public class MainActivity extends Activity {
- private WebView mWebView;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- // Receive broad Cast fromn External App
- IntentFilter filter = new IntentFilter("com.mysender.Data");
- registerReceiver(myReceiver, filter);
- }
- private MyReceiver myReceiver =new MyReceiver(){
- @Override
- public void onReceive(Context context, Intent intent) {
- String path = intent.getStringExtra("path");
- Toast.makeText(context,"Data Received from External App: " + path, Toast.LENGTH_SHORT).show();
- }
- };
- @Override
- protected void onDestroy() {
- super.onDestroy();
- unregisterReceiver(myReceiver);
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.example.app" >
- <uses-permission android:name="android.permission.INTERNET" />
- <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
- <application
- android:allowBackup="true"
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
- android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
- <activity
- android:name="com.example.app.MainActivity"
- android:label="@string/app_name" >
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- </manifest>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement