android P actions - app not receiving intent action in broadcastReceiver - android

What i am doing is making an app that when user uses google assistant to say "turn on my app" then it asked "do you want to turn on my app" and then user replies "yes" or "yes please" and i want it to open my app. I am expecting that a broadcastReciever will be called with the intent that the google assistant sent and i will know how to react. Lets see what i have done so far and i am testing this all on Android P emulator:
here is what the server side has on google:
then in the android manifest i have declared a broadcastreciever so that it can listen for the custom intent action i created above called action_intent_OPEN_CALL_MUSIC:
<receiver android:name=".receivers.MyGoogleAssistantReceiver">
<intent-filter>
<action android:name="action_intent_OPEN_CALL_MUSIC" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
when i then use the google assistant in the emulator no broadcast is received in the app, what am i doing wrong ?
public class MyGoogleAssistantReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.v("myTag","got an intent:" + intent.getAction()); //nothing hits here,why ?
}
}
do i have to add something in xml/actions.xml even though its all local ?

Related

Android: Auto Start issue cause not getting push notification

I have an app that have push notification feature. I notice that some of the device especially chinese phone like xiamoi,oppo,one plus etc having option for auto start and this control the push notification. Am not getting Push Notification when the app is not in background or in recent list.By default my app auto start is OFF
But am confused why the app like Flipkart,Amazon, Whatsapp, Hike the auto start is ON by default.
Is there is any option to set the auto start as ON by default
I think, better way is using default Android API features to run service after boot, not use custom features like used in chinese phones.
To make autrun by default Android way, you should add to mainfest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver
android:name=".BootReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
And write Boot receiver:
public class BootReceiver extends BroadcastReceiver {
public BootReceiver() {
// TODO Auto-generated constructor stub
}
#Override
public void onReceive(Context context, Intent intent) {
//Run your service here
}
}

How to make broadcast receiver to listen event for particular app in android?

I am developing an app which contain list of app, when user click of particular app from list shown to him he will directed to website from which he can download that app to listen app is successfully download I add a broadcast receiver in android menifest.xml.The problem is that broadcast receiver listen if any app downloaded in system as well as from my app also.what I want broadcast receiver should listen only events from app only when my app is open as well as closed.
here is my java code:-
public class Receiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// Check if the application is install or uninstall and display the message accordingly
if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) {
// Application Install
Log.e("Package Added:-", intent.getData().toString());
} else if (intent.getAction().equals("android.intent.action.PACKAGE_REMOVED")) {
Log.e("Package Removed:-", intent.getData().toString());
} else if (intent.getAction().equals("android.intent.action.PACKAGE_REPLACED")) {
Log.e("Package Replaced:-", intent.getData().toString());
}
}
}
here is my xml code:-
<receiver android:name=".Receiver">
<intent-filter android:priority="100">
<action android:name="android.intent.action.PACKAGE_INSTALL"/>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>
kinldy help me I am trying from a week plsss.
There is no way for you to know whether the package is installed by your app just with the information in the Intent received by your BroadcastReceiver. Technically, your app isn't installing anything, the system does that (third party apps do not have the privilege to install other apps).
You will have to check the package name from the Intent data and compare it to apps the user downloaded with your app. That's the best you can do.

Google Glass - Autostart Application on Boot

I just received a new google-glass from a company which wants it to support their employees while picking and packing goods in their warehouse. For this reason they need a Server Client application which really isn't the problem.
I never did something with the Glass before and i want to know if it is possible to run a custom Application on boot and to jail the user into it.
Yesterday i rooted the device which gives me full access but i don't know how to go on.
Thank you!
Yes, it is possible.
As you have rooted the device, so you can create system app that can be recognised by the reboot event. Rest of the steps are totally similar to android mobile.
How to do it:
If you need to know the steps you can search on the web or you can try the following:
First, you need the permission in your AndroidManifest.xml:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Also, in yourAndroidManifest.xml, define your service and listen for the BOOT_COMPLETED action:
<service android:name=".MyService" android:label="My Service">
<intent-filter>
<action android:name="com.myapp.MyService" />
</intent-filter>
</service>
<receiver
android:name=".receiver.StartMyServiceAtBootReceiver"
android:label="StartMyServiceAtBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Then you need to define the receiver that will get the BOOT_COMPLETED action and start your service.
public class StartMyServiceAtBootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent serviceIntent = new Intent(context, MySystemService.class);
context.startService(serviceIntent);
}
}
}
And now your service should be running when the phone starts up.

Callback after my application was installed?

Is there any callback / receiver / anything that gets called once when my application is installed?
For this, you have to make one application apart from your main application that can keep tracking about the install or uninstalled application from your device.
For this you need to register the Receiver.
<receiver android:name=".AppStatusReceiver" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
</intent-filter>
</receiver>
AppStatusReceiver.java
public class AppStatusReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "Intent: " + intent.getAction());
}
}
Note : If you are looking this to be manage from your main application callback then it is no possible.
There is no way for an app to run code when it was installed.
For other apps, you could create a BroadcastReceiver for ACTION_PACKAGE_ADDED, but as the docs explain, this won't work for the app that was newly installed:
Note that the newly installed package does not receive this broadcast.

Can we able to get installation result from Google Play page in Android?

Here is my question,
I need to redirect the user to specific app page (Google play page) from Page_One.Java. (Implemented)
The user successfully install that application from Google Play page, now it returns to previous page.(Implemented)
Now i need to get the response in Page_One.java, whether the app installation is success or failed. Is it possible to get the installation status?
You can check with the PackageManager if the application has been installed or not.
HERE you can find a working code that helps to find out if the application is properly installed or not.
You can register a broadcast receiver detecting a package added action like this :
<receiver android:name="com.example.InstalledReceiver" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
Then declare a broadcast receiver class
public class InstalledReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String installedPackage = intent.getDataString();
//Uri like package://com.example.myapp
}
}
In the onReceive method you will know if it was the correct application. However I am not sure if you can get the status on failure

Categories

Resources