bsorrentino / cordova-broadcaster

Cordova Plugin to allow message exchange between javascript and native (and viceversa)
MIT License
113 stars 53 forks source link

How to listening android.intent.action.PACKAGE_ADDED? #34

Closed CjoyHome closed 6 years ago

CjoyHome commented 6 years ago

Is it possible to receive the broadcast from android.intent.action.PACKAGE_ADDED?

bsorrentino commented 6 years ago

Really you could manage whatever events ... but, if such events are external ones, you have to re-route them (take a look at #17)

This mean that you have:

  1. register a listener in javascript
    window.broadcaster.addEventListener("android.intent.action.PACKAGE_ADDED", function (e) { 
               console.log("android.intent.action.PACKAGE_ADDED received."); 
     });
  2. properly configure android.intent.action.PACKAGE_ADDED and when receive event you can call
    LocalBroadcastManager.getInstance(context).sendBroadcastSync(intent);
CjoyHome commented 6 years ago
<application 
        android:icon = “ @drawable/ic_launcher”
         android:label = “ @string/app_name” >
        <receiver  android:name = “MyReceiver” >
            <intent-filter>
                <action  android:name = “android.intent.action.PACKAGE_ADDED” >
                    </action >
            </intent-filter>
        </receiver>
    </application>
public class MyReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
                 LocalBroadcastManager.getInstance(context).sendBroadcastSync(intent);
    }
}
CjoyHome commented 6 years ago

sorry, I may forgot to mention I am using Ionic 2.

this.broadcaster.addEventListener('android.intent.action.PACKAGE_ADDED').subscribe((event) =>

It is unsuccessful,

error: java.lang.RuntimeException: 
Unable to instantiate receiver io.ionic.starter.CDVBroadcaster: 
java.lang.ClassNotFoundException: 
Didn't find class "io.ionic.starter.CDVBroadcaster" 
on path: DexPathList[[zip file "/data/app/io.ionic.starter-1/base.apk"],
nativeLibraryDirectories=[/data/app/io.ionic.starter-1/lib/arm64, /system/lib64, /vendor/lib64]]
bsorrentino commented 6 years ago

I've no idea the origin of the error. I don't know the class io.ionic.starter.CDVBroadcaster the plugin class is org.bsc.cordova.CDVBroadcaster

I've to check, if you have anything that could help me (config.xml, snippet, ... ) please share it

CjoyHome commented 6 years ago

您好,我使用的是ionic2 的nactive,我想问下在ionic2 中怎么样使用这个插件动态的监听安装成功的广播,我希望的是当我在app中点击下载按钮,在下载完成后自动跳转到软件安装,在这个时候注册并启用监听,当我安装完成后,给我个安装成功的返回状态,然后我在进行下一步操作,请问这个如何实现,我查了很久,由于对安卓原生不熟悉,所以没成功。谢谢

CjoyHome commented 6 years ago

Sorry,My English is poor, now is the use of translation, I play Chinese is afraid of my expression is not clear, I am afraid that you can not understand translation.

CjoyHome commented 6 years ago

Hello, I use is ionic2 nactive, I would like to ask how to use this plugin dynamic monitor installation successful broadcast in ionic2, I hope that when I click the download button in app, when the download completes automatically jump to the software installation, registration at this time and enable listening, when I finished the installation then, give me a return to the state of installation is successful, then I in the next step, this is how to achieve, I look for a long time, because not familiar with the original Android, so there is no success. Thank you

bsorrentino commented 6 years ago

I'm arranging a ionic2 simple project so will be easier to understand how use this plugin

CjoyHome commented 6 years ago

OK,thank you

CjoyHome commented 6 years ago

May I listen to the android.intent.action.PACKAGE_ADDED now?

bsorrentino commented 6 years ago

@CjoyHome see this link (https://stackoverflow.com/a/18829680/521197)

The steps should be:

  1. Register a custom listener in your javascrist
    var listener = function( e ) {
     console.log( "onPackagedAdded received! " + e  );
    }
    window.broadcaster.addEventListener( "onPackagedAdded", listener);
  2. Configure a PackageAddedReceiver in your manifest.xml having the PACKAGE_ADDED intent filter
  3. Implement onReceive method on your PackageAddedReceiver java class and broadcasting the event to get it handled by javascript listener
    final Intent intent = new Intent("onPackagedAdded");
    
    Bundle b = new Bundle();
    // put data 
    intent.putExtras( b);
    
    LocalBroadcastManager.getInstance(this).sendBroadcastSync(intent);
bsorrentino commented 6 years ago

@CjoyHome

As promised an ionic3 sample project using broadcaster [https://github.com/bsorrentino/ionic-broadcaster-sample]()

CjoyHome commented 6 years ago

App into the background, can you receive the broadcast?

CjoyHome commented 6 years ago

Should I customize the plugin in the way you do it?

bsorrentino commented 6 years ago

I don’t know whether the app in background can receive message. This is an android matter, take a look here

If yes, I don’t think that such native event could be sent to interface during background. Probably you have to cache it and send when app back in foreground

Bhanu021 commented 5 years ago

how create a call recorder app in ionic 4

Bhanu021 commented 5 years ago

anyone please help ?

bsorrentino commented 5 years ago

Hi @Bhanu021

Why the a call recorder app is related to this plugin?

I think that you could have more help asking on stackoverflow