Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
CjoyHome opened this issue Dec 13, 2017 · 18 comments
Closed

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

CjoyHome opened this issue Dec 13, 2017 · 18 comments
Labels

Comments

@CjoyHome
Copy link

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

@bsorrentino
Copy link
Owner

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."); 
 });
  1. properly configure android.intent.action.PACKAGE_ADDED and when receive event you can call
LocalBroadcastManager.getInstance(context).sendBroadcastSync(intent);

@CjoyHome
Copy link
Author

CjoyHome commented Dec 14, 2017

<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
Copy link
Author

CjoyHome commented Dec 14, 2017

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
Copy link
Owner

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
Copy link
Author

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

@CjoyHome
Copy link
Author

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
Copy link
Author

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
Copy link
Owner

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

@CjoyHome
Copy link
Author

OK,thank you

@CjoyHome
Copy link
Author

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

@bsorrentino
Copy link
Owner

@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);
  1. Configure a PackageAddedReceiver in your manifest.xml having the PACKAGE_ADDED intent filter
  2. 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
Copy link
Owner

@CjoyHome

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

@CjoyHome
Copy link
Author

App into the background, can you receive the broadcast?

@CjoyHome
Copy link
Author

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

@bsorrentino
Copy link
Owner

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
Copy link

Bhanu021 commented Mar 8, 2019

how create a call recorder app in ionic 4

@Bhanu021
Copy link

Bhanu021 commented Mar 8, 2019

anyone please help ?

@bsorrentino
Copy link
Owner

Hi @Bhanu021

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

I think that you could have more help asking on stackoverflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants