Limbo for Android 33 - java

I am trying to port Limbo Emulator for Android 33. It keeps crashing at this line:
PendingIntent pi = PendingIntent.getActivity(service.getApplicationContext(), 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
From this block
private void setUpAsForeground(String text) {
if (MachineController.getInstance().getMachine() == null) {
Log.w(TAG, "No Machine selected");
return;
}
Intent intent = new Intent(service.getApplicationContext(), Config.clientClass);
PendingIntent pi = PendingIntent.getActivity(service.getApplicationContext(), 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel chan = new NotificationChannel(Config.notificationChannelID, Config.notificationChannelName, NotificationManager.IMPORTANCE_NONE);
NotificationManager notifService = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notifService.createNotificationChannel(chan);
builder = new NotificationCompat.Builder(service, Config.notificationChannelID);
} else
builder = new NotificationCompat.Builder(service, "");
mNotification = builder.setContentIntent(pi).setContentTitle(getString(R.string.app_name)).setContentText(text)
.setSmallIcon(R.drawable.limbo)
.setLargeIcon(BitmapFactory.decodeResource(service.getResources(), R.drawable.limbo)).build();
mNotification.tickerText = text;
mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
service.startForeground(notifID, mNotification);
}
from this file:
MachineService.java
I got it to kinda work by changing:
PendingIntent pi = PendingIntent.getActivity(service.getApplicationContext(), 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
To:
PendingIntent pi = PendingIntent.getActivity(service.getApplicationContext(), 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
The BIOS Screen Opens but, when I add an ISO or qcow2 it crashes. This makes me think its a storage issue and not a Intent Issue... can anybody help me please?
Here is the original project I'm trying to port:
Limbo

Related

How to display a notification on the lock screen on Android

After looking at the official document of the Android studio, I created a program that alerts me according to the situation I wanted.(Actually, I just copied and pasted it.)
However, notifications only appear in the top bar now.
I'd like to have a notification window appear on the lock screen where my phone is turned off.
A notification sound is coming when the cell phone is turned off.
Do I need to design a new window in xml?
Or is there a problem?
I'm sorry if the question is weird.I look forward to your advice. Thank you.
Here is my code (Notification Method)
private void showNoti() {
builder=null;
manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
manager.createNotificationChannel(
new NotificationChannel(CHANNEL_ID,CHANEL_NAME,NotificationManager.IMPORTANCE_DEFAULT)
);
builder = new NotificationCompat.Builder(this,CHANNEL_ID);
}else{
builder=new NotificationCompat.Builder(this);
}
Intent intent = new Intent(this, mapActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
Intent fullScreenIntent = new Intent(this, mapActivity.class);
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0,
fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent snoozeIntent = new Intent(this,mapActivity.class);
snoozeIntent.putExtra(EXTRA_NOTIFICATION_ID,0);
PendingIntent snoozePendingIntent =
PendingIntent.getBroadcast(this,0,snoozeIntent,0);
builder.setContentTitle("화재알림");
builder.setContentText("화재가 발생했습니다");
builder.setSmallIcon(R.drawable.fire);
builder.setContentIntent(pendingIntent);
builder.addAction(R.drawable.fire, getString(R.string.app_name),
snoozePendingIntent);
builder.setFullScreenIntent(fullScreenPendingIntent, true);
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
builder.setAutoCancel(true);
Notification notification = builder.build();
manager.notify(1,notification);
}

(Share Intent) External Share Not Working in Android 12

After Android 12 update share intent not working in Samsung S10 device.This code is properly working in below Android version 12 devices but could not find the reason why in
android 12 is filtering out.
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
// (Optional) If you want a preview title, set it with Intent.EXTRA_TITLE
sharingIntent.putExtra(Intent.EXTRA_TITLE, str_title);
sharingIntent.putExtra(Intent.EXTRA_TEXT, "https://www.cyranolab.media/msg/?q=507dddd6-8e43-11ec-9d11-061d7e6be791");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, str_title);
Intent receiver = new Intent(getActivityContext, UserSelectedShareBroadcast.class);
PendingIntent pendingIntent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
pendingIntent = PendingIntent.getActivity(getActivityContext,
0, receiver, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
}else {
pendingIntent = PendingIntent.getActivity(getActivityContext,
0, receiver, PendingIntent.FLAG_UPDATE_CURRENT);
}
Intent openInChooser = Intent.createChooser(sharingIntent, "Choose", pendingIntent.getIntentSender());
List<LabeledIntent> intentList = new ArrayList<>();
Intent externalEmailIntent = new Intent(getActivityContext, ExternalEmailShareActivity.class);
externalEmailIntent.putExtra("programId", programId);
externalEmailIntent.putExtra("sharedResourceId", sharedResourceId);
externalEmailIntent.putExtra("INBOX", "Inbox");
intentList.add(new LabeledIntent(externalEmailIntent, "Package Name", "Email to", R.drawable.ic_mail_outline));
// convert intentList to array
LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[0]);
openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
int REQUEST_SHARED_URL = 2;
getActivityContext.startActivityForResult(openInChooser, REQUEST_SHARED_URL);
}
I want to share my Programs to other Apps. I unable to share my program to other apps. Share intent not opened, After android 12 update.
Missing FLAG_IMMUTABLE
To declare that a given PendingIntent object is mutable or immutable, use the PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_IMMUTABLE flag, respectively. Above code Just i added this lines: Working fine now
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
pendingIntent = PendingIntent.getActivity(getActivityContext,
0, receiver, PendingIntent.FLAG_IMMUTABLE);
}else {
pendingIntent = PendingIntent.getActivity(getActivityContext,
0, receiver, PendingIntent.FLAG_UPDATE_CURRENT);
}

Notification disappearing if touched over it

I am building a notification which has ACCEPT and REJECT buttons but at the same time i also wants to open the activity when user touches over the notification. But in my case only both buttons working and when touched over the other parts than buttons it just disappears.
My efforts :
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
String NOTIFICATION_CHANNEL_ID = "BizPhone Channel";
int id = (int) System.currentTimeMillis();
Intent intent = new Intent(context, incoming_service.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra(Intent.EXTRA_PHONE_NUMBER, phoneNumber);
intent.putExtra(Intent.EXTRA_MIME_TYPES, callType);
intent.putExtra("NOTE", Integer.toString(id));
PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "BizPhone Notifications", NotificationManager.IMPORTANCE_HIGH);
// Configure the notification channel.
notificationChannel.setDescription("BizPhone related notifications");
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.RED);
notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
notificationChannel.enableVibration(true);
notificationManager.createNotificationChannel(notificationChannel);
}
// assuming your main activity
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID);
notificationBuilder.setAutoCancel(true)
.setCategory(Notification.CATEGORY_CALL)
.setOngoing(true)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_call_black_24dp)
.setPriority(Notification.FLAG_INSISTENT)
.setContentTitle(phoneNumber)
.setContentText("Incoming Call")
.setSound(alarmSound)
.setContentIntent(pendingIntent)
.setContentInfo("Call");
Intent accept = new Intent(context, incoming_service.class);
accept.setAction(incoming_service.ANSWER);
accept.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
accept.putExtra(Intent.EXTRA_PHONE_NUMBER, phoneNumber);
accept.putExtra(Intent.EXTRA_MIME_TYPES, callType);
accept.putExtra("NOTE", Integer.toString(id));
PendingIntent pendingIntentYes = PendingIntent.getService(context, 10, accept, PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.addAction(R.drawable.ic_permission_granted_24dp, "ACCEPT", pendingIntentYes);
Intent decline = new Intent(context, incoming_service.class);
decline.setAction(incoming_service.REJECT);
decline.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
decline.putExtra(Intent.EXTRA_PHONE_NUMBER, phoneNumber);
decline.putExtra(Intent.EXTRA_MIME_TYPES, callType);
decline.putExtra("NOTE", Integer.toString(id));
PendingIntent pendingIntentNo = PendingIntent.getService(context, 11, decline, PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.addAction(R.drawable.ic_call_end_black_24dp, "REJECT", pendingIntentNo);
//notificationBuilder.build().flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(id, notificationBuilder.build());
I have tried by looking at other threads too but it did not help. Any help would be appreciated and thanks in advance.
Change
setAutoCancel(true)
to
setAutoCancel(false)
Just try to add :
PendingIntent contentIntent = builder
.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT
| PendingIntent.FLAG_ONE_SHOT);
I am answering my own question for future incoming users.
Why notification was disappearing on touch ( outside of 2 buttons but still on notification )
Because the base pendingintent was not a activity and it was a service. You can notice the code above. It should have been like :
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClass(context, CallActivity.class);
intent.putExtra(Intent.EXTRA_PHONE_NUMBER, phoneNumber);
intent.putExtra(Intent.EXTRA_MIME_TYPES, callType);
And the 2 buttons code and their pendingintent which is service was okay.

Android foreground service notification not showing in status bar

I have tried various solution here on SO and can't seem to get any of them to work. The notification simply will not show. Can anyone point out where possible issues in my code could be?
private void startRunningInForeground() {
setupNotificationChannel();
Intent showTaskIntent = new Intent(getApplicationContext(), MainActivity.class);
showTaskIntent.setAction(Intent.ACTION_MAIN);
showTaskIntent.addCategory(Intent.CATEGORY_LAUNCHER);
showTaskIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(
getApplicationContext(),
0,
showTaskIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, SERVICE_NOTIFICATION_CHANNEL);
builder.setSmallIcon(R.drawable.ic_stat_ic_logo);
builder.setContentTitle(getString(R.string.merge_notif_title));
builder.setContentText(getString(R.string.merge_notif_description));
builder.setContentIntent(contentIntent);
builder.setWhen(System.currentTimeMillis());
builder.setAutoCancel(false);
builder.setOngoing(true);
startForeground(NOTIFICATION_ID, builder.build());
}
private void setupNotificationChannel() {
// Only run this on versions of Android that require notification channels.
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
return;
}
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if(notificationManager == null) {
return;
}
NotificationChannel cachingChannel = new NotificationChannel(SERVICE_NOTIFICATION_CHANNEL,
getString(R.string.merge_channel), NotificationManager.IMPORTANCE_HIGH);
cachingChannel.setDescription(getString(R.string.merge_channel_description));
cachingChannel.enableLights(false);
cachingChannel.enableVibration(false);
notificationManager.createNotificationChannel(cachingChannel);
}
Not receiving any any error messages and the notification channel is being created because I see it in the app settings.
What does your startForeground do?
try modify this and make sure your os is > Android 8.0
btw the Channel only needs to be created once.
PendingIntent contentIntent = PendingIntent.getActivity(
getApplicationContext(),
NOTIFICATION_ID, <---
showTaskIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
startForeground(NOTIFICATION_ID, builder.build());
notificationManager.notify(NOTIFICATION_ID, builder.build()); <--
Maybe because of Android O bg service restrictions
//Start service:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(new Intent(this, YourService.class));
} else {
startService(new Intent(this, YourService.class));
}
So I was able to get it to work by extending Service instead of IntentService. I cannot give an explanation as to why this worked, but everything is now working as expected.

Multiple push notifications on android with wrong icon size

Let me preface this post with the fact that I am new to the android programming.
When I issue a notification, the phone shows two notifications for the same thing. The only difference is, the icons look different and they do different things. The first will do nothing when you select it. The other opens the app to the correct page.
I used to only get one notification until I edited this method. I'm not sure what I did but perhaps someone could tell me why this sends 2 and how to fix it?
The other question I have is that on both notifications on the phone, the icon is zoomed in (or too big). How do you make the push notification icon the correct size?
Here is my method
private static void generateNotification(Context context, String message) {
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context, FriendGroupActivity.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;
// Vibrate if vibrate is enabled
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
}
Try this :
private void generateNotification(Context context, String message) {
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
String appname = context.getResources().getString(R.string.app_name);
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
Notification notification;
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(context, myactivity.class), 0);
// To support 2.3 os, we use "Notification" class and 3.0+ os will use
// "NotificationCompat.Builder" class.
if (currentapiVersion < android.os.Build.VERSION_CODES.HONEYCOMB) {
notification = new Notification(icon, message, 0);
notification.setLatestEventInfo(context, appname, message,
contentIntent);
notification.flags = Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
} else {
NotificationCompat.Builder builder = new NotificationCompat.Builder(
context);
notification = builder.setContentIntent(contentIntent)
.setSmallIcon(icon).setTicker(appname).setWhen(0)
.setAutoCancel(true).setContentTitle(appname)
.setContentText(message).build();
notificationManager.notify(0 , notification);
}
}
Hope this helps.This works for me.

Categories

Resources