Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. package com.mysender;
  2.  
  3.  
  4. import android.content.ComponentName;
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.support.v7.app.AppCompatActivity;
  8.  
  9. public class MainActivity extends AppCompatActivity {
  10.  
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.activity_main);
  15. final Intent intent=new Intent();
  16. intent.setAction("com.mysender.Data");
  17. intent.putExtra("path", "/Download/income_tax_return.pdf");
  18. intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
  19. intent.setComponent(new ComponentName("com.example.app","com.example.app.MainActivity"));
  20. sendBroadcast(intent);
  21.  
  22. }
  23. }
  24.  
  25. <?xml version="1.0" encoding="utf-8"?>
  26. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  27. package="com.mysender">
  28. <application
  29. android:allowBackup="true"
  30. android:icon="@mipmap/ic_launcher"
  31. android:label="@string/app_name"
  32. android:roundIcon="@mipmap/ic_launcher_round"
  33. android:supportsRtl="true"
  34. android:theme="@style/AppTheme">
  35. <activity android:name=".MainActivity">
  36. <intent-filter>
  37. <action android:name="android.intent.action.MAIN" />
  38.  
  39. <category android:name="android.intent.category.LAUNCHER" />
  40. </intent-filter>
  41. </activity>
  42. </application>
  43.  
  44. </manifest>
  45.  
  46. ackage com.example.app;
  47.  
  48. import android.app.Activity;
  49. import android.content.Context;
  50. import android.content.Intent;
  51. import android.content.IntentFilter;
  52. import android.os.Bundle;
  53. import android.widget.Toast;
  54.  
  55. public class MainActivity extends Activity {
  56.  
  57. private WebView mWebView;
  58.  
  59. @Override
  60. protected void onCreate(Bundle savedInstanceState) {
  61. super.onCreate(savedInstanceState);
  62. setContentView(R.layout.activity_main);
  63.  
  64. // Receive broad Cast fromn External App
  65. IntentFilter filter = new IntentFilter("com.mysender.Data");
  66. registerReceiver(myReceiver, filter);
  67.  
  68. }
  69. private MyReceiver myReceiver =new MyReceiver(){
  70. @Override
  71. public void onReceive(Context context, Intent intent) {
  72. String path = intent.getStringExtra("path");
  73. Toast.makeText(context,"Data Received from External App: " + path, Toast.LENGTH_SHORT).show();
  74.  
  75. }
  76. };
  77.  
  78. @Override
  79. protected void onDestroy() {
  80. super.onDestroy();
  81. unregisterReceiver(myReceiver);
  82.  
  83. }
  84. }
  85.  
  86. <?xml version="1.0" encoding="utf-8"?>
  87. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  88. package="com.example.app" >
  89. <uses-permission android:name="android.permission.INTERNET" />
  90. <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  91. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  92. <application
  93. android:allowBackup="true"
  94. android:icon="@drawable/ic_launcher"
  95. android:label="@string/app_name"
  96. android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
  97. <activity
  98. android:name="com.example.app.MainActivity"
  99. android:label="@string/app_name" >
  100. <intent-filter>
  101. <action android:name="android.intent.action.MAIN" />
  102. <category android:name="android.intent.category.LAUNCHER" />
  103. </intent-filter>
  104. </activity>
  105. </application>
  106. </manifest>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement