1
I want make like this
2
3
to hide notification like doge rat
private void startMyOwnForeground()
{
String NOTIFICATION_CHANNEL_ID = "example.permanence";
String channelName = "Battery Level Service";
NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_NONE);
chan.setLightColor(Color.BLUE);
chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
assert manager != null;
manager.createNotificationChannel(chan);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);
Notification notification = notificationBuilder.setOngoing(true)
.setContentTitle("Battery Level")
.setPriority(NotificationManager.IMPORTANCE_MIN)
.setCategory(Notification.CATEGORY_SERVICE)
.build();
startForeground(1, notification);
}
this my code for ground service
Related
I am not able to display the slice in slice viewer app when the setPrimaryAction is not set in the row builder
list(context, sliceUri, ListBuilder.INFINITY)
{
header {
title ="News Content"
}
row {
title = "news genre"
subtitle = "first new headlines"
}
}
The above snippet does not display slice in sliceviewer
whereas if I change the code by adding primaryAction in one of the row. Slice is getting rendered but for my usecase, I don't want to set any action
list(context, sliceUri, ListBuilder.INFINITY)
{
header {
title ="News Content"
}
row {
title = "news genre"
subtitle = "first new headlines"
setPrimaryAction = SliceAction.create(
PendingIntent.getActivity(
context, 0, Intent(context, MyActivityClass::class.java), 0
),
IconCompat.createWithResource(context,
R.drawable.ic_launcher_foreground),
ListBuilder.ICON_IMAGE,
"Open App"
)
}
}
The above snippet displays slice in sliceviewer
I would like to understand why do we need to set primaryAction. There might be few use-cases where we don't need any action
As per the Android's official documentation, Slice actions are considered as the most basic element of the slice template.
So when we don't set the primary action , the following exception occurs
java.lang.IllegalStateException: A slice requires a primary action; ensure one of your builders has called #setPrimaryAction with a valid SliceAction.
The purpose of slices are to help users perform tasks faster by enabling engagement outside of the fullscreen app experience. Since it is user interactive, I guess that's why they have mandated a basic action.
I am trying to update the background color of a Label inside a TableViewRow. I am using a View/Controller for the rows, creating them in code and appending them as an array to the TableView. Using onClick of the TableViewRow and Label.setBackgroundColor() inside the TableViewRow controller.
ExampleRow.xml
<TableViewRow id="exampleRow" class="exampleClass" onClick="exampleClick">
<Label id="exampleLabel" text="test" />
</TableViewRow>
ExampleRow.js
var test = 1;
function exampleClick(e) {
if(test == 1) {
$.exampleLabel.setBackgroundColor('#0f0');
test = 0;
} else {
$.exampleLabel.setBackgroundColor('#fff');
test = 1;
}
}
ExamplePage.xml
<TableView id="exampleTable" />
ExamplePage.js
var tableViewRows = [];
for(var i = 0; i < 5; i++) {
tableViewRows.push(
Alloy.createController('exampleRow', {}).getView()
);
}
$.exampleTable.setData(tableViewRows);
The problem is this does not work on the first page as soon as the app loads. If I scroll the TableViewRows outside of the screen and back in, the background color change works. If an alert box is popped up the background change works. But after first app load, the background color will not change. It also works if we use appendRow for each row, but this is substantially slower.
appendRow fix example:
for(var i = 0; i < 5; i++) {
$.exampleTable.appendRow(
Alloy.createController('exampleRow', {}).getView()
);
}
appending the rows individually sometimes fixes the bug (not every row), but for our list takes 5-8 seconds to display the table, rather than <1second using setData*
Example of the real app not working:
Example of the real app working:
This occurs after having an alert box displayed or scrolling the rows out and back in to the screen, or using appendRow for each row
Methods I have attempted to fix (did not fix):
using animations
removing the label then recreating and adding a new label in code
removing class from the TableViewRow
I am using Titanium SDK 5.0.2.GA and compiling on android 5.1.1.
Try to use click event of tableView instead of tableViewRow :
<TableView onClick="yourTableViewClickEvent"></TableView>
and then define what logic will be executed inside this function callback :
function yourTableViewClickEvent(e){
// access selected row
var currentSelectedRow = e.row;
// current selected Label we assume here that the row contain a label as first child (exactly what you have in your row definition
var currentLabel = currentSelectedRow.children[0]
// change label background color
currentSelectedRow.backgroundColor = "#0f0"
// You can even (i know it is no good to do that :)) test if the color is white or #0f0 like so
if(currentSelectedRow.backgroundColor == "#fff")
currentSelectedRow.backgroundColor = "#0f0"
else
currentSelectedRow.backgroundColor = "#fff"
}
I have a simple counter app which displays the button count in a TextView. This is also sent in an ArrayList of an ArrayAdapter to log the time the button was pressed. At the moment, every time the button is pressed it logs it. Although, i want it to only log the last time it is pressed in a series of pressed.
for example: if the button is pressed 3 times in the space of 3 second i want the log to just show 1 line displaying '3' instead of 3 lines displaying '1'. Then if it is pressed another 5 times in 3 seconds it shows '3' on one line and '5' on the next. At the moment it would display 8 lines all with '1' on it.
ill need some sort of onLastClickListener or something along those lines but i can't work it out...
There's no on"last"clickListener... You have to teach an onClickListener how to understand what a last click is. Example to get you started:
View.OnClickListener listener = new View.OnClickListener() {
long lastClickTime = 0;
int countClicks = 0;
#Override
public void onClick(View v) {
long newClickTime = System.currentTimeMillis();
if((newClickTime - lastClickTime) <= 3000){
countClicks++;
}else{
lastClickTime = newClickTime;
countClicks = 1;
}
//Do Something with countClicks;
}
};
I have a Activity in android that has 4 buttons.
The first 3 buttons fetches a json data from a weather API for 1 day, next 5 days and next 10 days respectively.
I have a 4th button placed at the bottom of the screen, which takes user to second activity.
I want to restrict the entry of user to second Activity if no button from top 3 is clicked.
If the data is fetched, I mean any one of the top 3 buttons have been clicked, allow him to go to second activity on 4th button click else show a message.
How can i check on click of 4th button if any of the top 3 buttons have been clicked before?
Thanks
Put a boolean field in your activity, name it clicked and set it to false on the onCreate method of your first activity, then in the onClick method of your 3 buttons, set it to true,
and in the onClick method of your 4th button check it, if it's true go startActivity, else launch a Toast
You can make the 4th button look disable in "OnCreate" with the function "setEnabled"(may be wrong),
and then just set "setOnClickListener" for the 4th button when you click any of the others.
ps.
Can provide code example if needed.
Why don't you use if statement? You can keep the clicked count data under the first three buttons. Like this;
import java.util.stream.*;
int[] btnMemory = new int[4];
button1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
btnMemory[0] = 1;
// your code
}
});
after, you can check it with if statement under 4th button;
button4.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
int sum = IntStream.of(btnMemory).sum();
if(sum >= 3)
// your code
}
});
Let me try to explain my question in detail.
I have 5 tabs and my Tab class is run after the Splash screen of my application, and the first tab will be displayed.
In my first tab, I have a class that contains a TextView that will display certain text under some condition (related to profile keyed in by the user in another class).
TextView duration = (TextView)view.findViewById(R.id.duration);
duration.setText(durationNumber);
if(week <= 12)
{
durationNumber = "Less than 12 weeks";
}
else
{
durationNumber = "More than 12 weeks";
}
When I run my application, the text does not appear, unless i navigate to other tabs and return to the first tab. I googled around and couldn't find a solution. I've tried using SharedPreferences but it didn't work. Perhaps I did it wrongly.
Why is this happening and how can I fix this?
What is the initial value of durationNumber? Is it null before it is set in the if-else loop? If it is null then the TextView will not appear (as there is no value to display).
You will have to set the TextView text again after the if-else loop. Try this...
TextView duration = (TextView)view.findViewById(R.id.duration);
if(week <= 12) {
durationNumber = "Less than 12 weeks";
} else {
durationNumber = "More than 12 weeks";
}
duration.setText(durationNumber);