Atooma Intent based trigger - android

I am trying out the Atooma SDK. They provide an abstract class IntentBasedTrigger for creating triggers that fires when the intent fires. The class has an abstract method
public String getIntentFilter() throws RemoteException
In the docs (http://www.atooma.com/developers#start/trigger) They use this with a standard Android intent. However, I want to use it with a custom Intent, so I made up a string and returned it from getIntentFilter. However, this does not work (I can't be more specific at the moment) which leads me to believe that defining intents is a bit more complicated?

IntentBasedTriggers works with custom Intent as well.
I am part of the Atooma team, unfortunally we don't have a plugin sample with IntentBasedTrigger, but you can see the SnapBack plugin using it
Here is the source code
https://github.com/SnapbackLabs/AtoomaPlugins/blob/master/AtoomaBlowDetectionPlugin/src/com/atooma/plugin/blow/TR_BlowDetectionSensorBased.java#L92

Related

Open an app from a JobService without "Display Over Other Apps" permission

I am new to android development. I've been trying to open an app from a JobService that is scheduled from the onReceive() method of an implicit broadcast-receiver, declared in my manifest.
From some posts, I found that one can use the packageManager.getLaunchIntentForPackage() method and then use it to launch said package by starting a new activty with context.startActivity(), so I declared the function below:
fun openApp(packageName: String, context: Context){
val startIntent: Intent? =
context.packageManager.getLaunchIntentForPackage(packageName)
startIntent?.addFlags(
Intent.FLAG_ACTIVITY_REORDER_TO_FRONT or
Intent.FLAG_ACTIVITY_NEW_TASK
);
context.startActivity(startIntent)
}
When used on the MainActivity file, this function works as expected, but when I try using it on my JobService, I noticed that it only works if my app has the Display Over Other Apps permission.
Is this to be expected? Is there any way to contourn this requirement? Is this because of the way I am passing the context in my openApp() function?
Thx in advance!
Thanks to CommonsWare's comments, I've found the documentation I needed:
Restrictions on starting activities from the background.
In my use case, I needed to cancel a call to a specific number and open my app instead, so I adapted my code to take advantage of the CallRedirectionService class, which is treated as an exception and therefore can start activities from the background.

Using Custom Push Broadcast Receiver in Android

According to the guide posted here I'm trying to implement my own BroadCastReceiver but in the PushManager class, there doesn't seem to be preHandlePush() and postHandlePush() defined. Am I using some outdated version of the library which I took from here? or am I missing something else?
I've update the guide (http://docs.pushwoosh.com/docs/android-faq#using-custom-push-broadcast-receiver-in-android), please take a look. These functions were moved to PushManagerImpl class.
i.e.
Bundle pushBundle = PushManagerImpl.preHandlePush(context, intent);

android Intent Selector

I am going through the API of the Intent class in Android, and I find a method called setSelector().
From its description, I get the idea that in addition to the actual intent, a second level intent is added. Also, instead of the actual intent, the selector intent will be used for finding entities who can handle it.
I am finding it hard to follow the browser example they have given. Can anyone give a simpler example of why the selector is useful ?
Thanks.

Calling an Application Activity from a Library Project in Android

Ok,
So I'm making a library project of UI elements. The Library has some activities which are based of ActionBarSherlock which is a backwards compatibility library for the action bar in android. In these activities I would like to have a button in the action bar which will take the user home regardless of which activity they are using in the Library project.
Some terminology. The 'library' refers to the Android UI library project I'm working on. The 'Application' refers to whatever customer a developer might be using with the Library included.
Usually, when you make an activity and you want to call another, you would do something like this.
intent = new Intent(this, WhateverMyActivityName.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Simple enough. But here's the tricky bit. Android Libraries have little to no knowledge of what application is using them. So 'WhateverMyActivityName.class' is useless as there is no way to predict what the developers application will call their activities.
I need to replace
intent = new Intent(this, WhateverMyActivityName.class);
with something like this
intent = new Intent(this, getApplication().MainActivity().getClass());
or possibly use some sort of intent action which will call the main Activity in the application (Intent.ACTION_MAIN or Intent.CATEGORY_LAUNCHER)
So in short: How do I get an applications main activity from a library project?
We can use reflection to get class object.
Class.forName("com.mypackage.myMainActivity")
Add this code in Library project to call,
try {
Intent myIntent = new Intent(this,Class.forName("com.mypackage.myMainActivity"));
startActivity(myIntent );
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
"com.mypackage.myMainActivity" is the Activity present in Main project, that we need to call from its Library project.
The application calls some method in your library providing the Intent to be invoked, or providing the Class of the activity to be invoked. Your library stores that someplace and uses it.
Your assumption that the right answer is "Intent.ACTION_MAIN or Intent.CATEGORY_LAUNCHER" may be inaccurate. For example, some apps have that be a splash screen activity (which is an issue in its own right, but that's beside the point), and that would not be where a home affordance within the app should go.
You can get the list of activities using the code mentioned in the this post. After that loop through the resolveinfo and check the intenet filter to find the activity with your desired intent action.

android IntentService what can be wrong when intent is empty?

hi
After creating intents for month now i suddenly
hit the wall when in my Notification PendingIntent, i did this:
Intent intent = new Intent(getApplicationContext(), SendFileService.class);
intent.putExtra("uuid", "123-456-34");
The SendFileService is an IntentService.
To my surprise in the IntentService onHandleIntent the extras.getString("uuid");
was null.
what can possible be the reason .
I even added an action to test but still the same.
Im clearly did something wrong or missing some knowledge about this.
Any ide?
From the docs
The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Categories

Resources