(Share Intent) External Share Not Working in Android 12 - java

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);
}

Related

Limbo for Android 33

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

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);
}

Running a function after the app opens from the background after notification click

I'm pretty new to Android development. I have been able to get a notification to pop up while the app is in the background. When I click on it, it successfully loads the application backup. However I want to load an Alert from the page but only when it is opened from a notification click.
Here is the code for generating the notification. Any help would be appreciated.
private void getNotificationForPasswordChange() {
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "Hello";// The user-visible name of the channel.
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
if (mNotificationManager != null)
mNotificationManager.createNotificationChannel(mChannel);
}
Bitmap icon = BitmapFactory.decodeResource(getResources(),
R.mipmap.ic_launcher);
Intent i=new Intent(this, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent mainIntent = PendingIntent.getActivity(this, 0,
i, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("Pronto Tracker")
.setTicker("Pronto Tracker")
.setContentText("Cannot connect to server. Location is not being updated.")
.setSmallIcon(R.mipmap.ic_pronto_logo)
.setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false))
.setOngoing(true).setContentIntent(mainIntent).
build();
mNotificationManager.notify(Constants.PASSWORD_CHANGE_NOTIFICATION_ID, notification);
}
You can pass the alert message with notification PendingIntent. Add the message or value you want to show as alert in PendingIntent .putExtra() and also specify the activity in PendingIntent where you want to show the alert in form of dialog or anything.
Intent intent = new Intent(Application.getAppContext(), MainActivity.class);
intent.putExtra("is_notification", true);
intent.putExtra("alert_message", "Hello World!");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent lowIntent = PendingIntent.getActivity(mContext, 100, intent, PendingIntent.FLAG_CANCEL_CURRENT);
After that add the PendingIntent to your notification.
Second thing you need to do is to get the data from the Intent when user taps on notification.
In your MainActivity add the following code to get data from Intent:-
if (getIntent() != null) {
String message = getIntent().getStringExtra("alert_message");
boolean isNotification = getIntent().getBooleanExtra("is_notification", false);
if(is_notification){
// show alert
}
}
You should use onCreate function on your MainActivity
Add this code to parce your intent:
Intent receivedIntent = getIntent();

on click of notification "launching activity" has extras as null, when app is in foreground or back ground in Android api 28 (pie)

Below is my code for pending intent for Android API level greater then 8:
Intent intent = new Intent(context, NotificationActivityBDO.class);
intent.putExtra("requestNotifyData", requestData);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent =
PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
String CHANNEL_ID = chanelID;// The id of the channel.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String programId = BankBrandingUtil.getProgramIdForBranding(context);
Log.d(TAG, "programId: " + programId);
icon = R.drawable.pn_icon;
CharSequence name;
name = "Transactions";// The user-visible name of the channel.
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
mChannel.setDescription(context.getResources().getString(R.string.lbl_iap_notification_channel_desc));
getNotificationManager(context).createNotificationChannel(mChannel);
}
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher);
//Notification.Builder builder = new Notification.Builder(context);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID);
builder.setContentIntent(contentIntent);
builder.setLargeIcon(bitmap);
builder.setSmallIcon(icon);
builder.setTicker(tickerText)
.setContentTitle(title)
.setContentText(text);
builder.setOnlyAlertOnce(true);
builder.setAutoCancel(true);
builder.setWhen(when);
Notification notification = builder.build();
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
Log.v(TAG, "notifiTag: " + notifiTag);
Log.v(TAG, "notifiId: " + notifiId);
getNotificationManager(context).notify(notifiTag, notifiId, notification);
In NotificationActivityBDO i m getting extras as below:
Bundle extras = activity.getIntent().getExtras();
if (extras != null) {
requestData = (RequestData) extras.getSerializable("requestNotifyData");
}
Above code is working fine for below 8 and recently my device got update to pie (Android version 9), notification is rendered and on click I see in launching activity extras as null.
Irrespective of app in background or foreground I'm getting requestMoneyData as null and when debugging I see extras as "empty parcel" and this happened only in Android version 9 and its working fine in below Android 9.
Any help is appreciated to resolve the above problem.
Setting extras with Bundle:
Bundle bundle = new Bundle();
bundle.putSerializable("name", requestList);
intent.putExtra("notification", bundle);
Getting extras in activity:
intent.extras.getBundle("notification").getSerializable("name")
Please use send data
intent.setData(Uri.parse("here url will be there"))
to get data
final String fcm_message = intent.data.toString()

Cancelled Notification being redelivered when other notification is touched. Android

I am having an issue where, no matter what notification the user touches, I am always receiving the same notification, even though it is cancelled.
The first notification a user touches is the only notification that will ever be delivered to my pending intent, until device reboot (then the first touched notification becomes the new Hotel California notification).
Here is how I am constructing the notifications:
final Bundle extras = new Bundle();
final int notificationId = Integer.parseInt(payload.getObjectId());
extras.putInt(NOTIFICATION_ID, notificationId);
final Intent intent = new Intent(context,
PushNotificationLauncherActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtras(extras);
final NotificationCompat.Builder builder = new NotificationCompat.Builder(
context);
builder.setContentTitle(context.getString(R.string.app_name));
builder.setContentText(payload.getText());
builder.setSmallIcon(R.drawable.icon_launcher);
builder.setAutoCancel(true);
final PendingIntent pIntent = PendingIntent.getActivity(context, 0,
intent, 0, extras);
builder.setContentIntent(pIntent);
final Notification notification;
if (Build.VERSION.SDK_INT < 16) {
notification = builder.getNotification();
} else {
notification = builder.build();
}
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(notificationId, notification);
Then I have this in my PushNotificationLauncherActivity:
final Bundle extras = getIntent().getExtras();
final int notificationId = extras
.getInt(SocialcastGoogleCloudMessageReceiver.NOTIFICATION_ID);
final NotificationManager notificationManager = (NotificationManager) this
.getSystemService(NOTIFICATION_SERVICE);
// please go away
notificationManager.cancel(notificationId);
Log.d(PushNotificationLauncherActivity.class.getSimpleName(),
"Touched notification ID: " + String.valueOf(notificationId));
No matter which notification I touch, in the log Touched notification ID: 1234 will always show, even if the notification I touch on has an ID of 56789.
I highly doubt it is an issue with my test-device, but incase it helps; I am using a 2013 Nexus 7 with KitKat 4.4.4 with the Dalvik runtime (not ART) Build KTU84P.
Pass your notificationId as the request code here:
final PendingIntent pIntent = PendingIntent.getActivity(context, 0,
intent, 0, extras);
Change this to:
final PendingIntent pIntent = PendingIntent.getActivity(context, notificationId,
intent, 0, extras);
When comparing two Intent instances, the included Bundles are not compared. So, from android's point of view, the two intents are the same.
Interestingly, the reqCode (second argument in PendingIntent.getActivity(...)) is compared. And this should render your Intents unique.

Categories

Resources