Permissions Bluetooth Android Maui - bluetooth

Is there a possibility to allow Bluetooth for Android when starting the app in Maui. Not with a button. Thank you .
I made an app with a button to authorize Bluetooth .

Just as Jason said, you can put your code about request the bluetooth permission in some lifecycle events.
Such as in the mainpage's onappearing method:
protected override void OnAppearing()
{
// the code about request permission
base.OnAppearing();
}
Or in the /Platfrom/Android/MainActivity.cs:
protected override void OnCreate(Bundle saveInstanceState)
{
base.OnCreate(saveInstanceState)
//the code about request permission
}

Related

Is there a way to test adMob ads with real unitIDs without uploading the app to Play Console?

My app has many types of ads (banner, transitions, rewarded video etc) in it. I have developed my app with Android Studio.
I test them all ads with test IDs as Google says.
After being confident that ads are working, I have changed test IDs to real IDs.
When I run the app on a phone physiacally connected to my PC, the ads are not shown. Some documents say that "real unitIDs never work unless the app is downloaded from Play Store source". That means I have to upload my app to Play Console each time to test real IDs.
But, loading the app to Play Console for test puprpose is not applicable because;
It takes long time to come alive (review period)
If I even accept to wait for that review period, when the app become alive, the users may download the bugy app because it is for test purpose and not a confident version.
You may say, if the app works with test IDs then it will work with real IDs bu it is not true.
Because my app works well with test IDs. When I switch to real IDs, banners keeps working but rewarded video ads doesn't.
My admob account and all adUnits seems ok. This is not an issue about my adMob account.
So the question is that, is there a way to test my app with admob's real unitIDs without uploading the app to Play Console and download it from Play Store?
Thanks,
Yes, you can test your Live Ids.
put this block of code in your splash activity (first activity), run your app you will get something like this in log, test_id replace this in your code...
I/Ads: Use RequestConfiguration.Builder.setTestDeviceIds(Arrays.asList("test_id"))
List<String> testDeviceIds = Arrays.asList("test_id");
RequestConfiguration configuration =
new RequestConfiguration.Builder().setTestDeviceIds(testDeviceIds).build();
MobileAds.setRequestConfiguration(configuration);
ref:
https://developers.google.com/admob/android/test-ads
for Rewareded interstial ads try this code:
make your class... implements OnUserEarnedRewardListener.
if anything goes wrong you will get error message in onAdFailedToLoad, using loadAdError.getMessage();
private RewardedInterstitialAd rewardedInterstitialAd;
#Override
public void onUserEarnedReward(#NonNull RewardItem rewardItem) {
Log.i(TAG, "onUserEarnedReward");
// TODO: Reward the user!
}
public void loadRewardedAd() {
// Use the test ad unit ID to load an ad.
RewardedInterstitialAd.load(MainActivity.this, getString(R.string.rewarded_interstitial_id),
new AdRequest.Builder().build(), new RewardedInterstitialAdLoadCallback() {
#Override
public void onAdLoaded(RewardedInterstitialAd ad) {
rewardedInterstitialAd = ad;
rewardedInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback() {
/** Called when the ad failed to show full screen content. */
#Override
public void onAdFailedToShowFullScreenContent(AdError adError) {
Log.i(TAG, "onAdFailedToShowFullScreenContent");
}
/** Called when ad showed the full screen content. */
#Override
public void onAdShowedFullScreenContent() {
Log.i(TAG, "onAdShowedFullScreenContent");
}
/** Called when full screen content is dismissed. */
#Override
public void onAdDismissedFullScreenContent() {
Log.i(TAG, "onAdDismissedFullScreenContent");
}
});
}
#Override
public void onAdFailedToLoad(LoadAdError loadAdError) {
Log.e(TAG, "onAdFailedToLoad");
}
});
}

No apps can perform this action. Share button Android Studio

I am trying to implement a share button in my android app which shares one image from the app to any other app of users choice. When I click on the share button , I get a dialog saying "No apps can perform this action". I am getting my image using Picasso from a uri stored in Realtime Firebase.TIA
This is my code snippet:
share.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent shareIntent = new Intent();
shareIntent.setPackage("com.package");
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share"));
}
});
Update:
I removed the line : shareIntent.setPackage("com.package");
And now it shows me the list of apps. But when i try to share the image usng whatsapp it says file format not supported.

Clear exo player notification when app stops from recent apps in android studio

I am developing an app for radio streaming using exoplayer library. So, I want to clear(delete) exoplayer notification bar (with play/stop buttons) when I close the app(from recent apps e.t.c). Now, I close the app but the notification bar still appears and doesn't close with swipe left/right.
I tried the following source code but it doesn't work (i tried to run the lines of the source code separately from the methods but I can't solve the problem).
public class RadioService extends Service {
......
.......
......
public void onTaskRemoved(Intent rootIntent) {
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancel(NOTIFICATION_ID);
stopForeground(true);
notificationManager.cancelAll();
}
public void onDestroy() {
super.onDestroy();
stopForeground(true);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancel(NOTIFICATION_ID);
}
}
I declared it in AndroidManifest.xml too.
Any help please?
Check this answer How to kill a foreground service along with the application and an example
https://androidwave.com/foreground-service-android-example/
at android 8 and above you have to use foreground service.
Add a small delay after the clear of notification and before killing the app or create a function that will inform you the notification is cleared

InterstitialAd not working with Windows Phone 10 (UWP - Windows 10)

I cant' get InterstitialAd to work in my UWP app when running on the Windows Phone Emulator (Note that I haven't tried it yet on actual real phone)
It works as expected when I run my UWP app in the Simulator or Local Machine as a Windows Store app.
Any ideas?
Thanks.
UPDATE - 1
Here is the code I use to display the InterstitialAd. In my MainPage.xaml.cs I have the following code:
public sealed partial class MainPage : Page
{
private InterstitialAd interstitialAd;
public MainPage()
{
this.InitializeComponent();
// Instantiate the interstitial video ad
interstitialAd = new InterstitialAd();
// Attach event handlers
interstitialAd.ErrorOccurred += OnAdError;
interstitialAd.AdReady += OnAdReady;
interstitialAd.Cancelled += OnAdCancelled;
interstitialAd.Completed += OnAdCompleted;
}
}
// This is an event handler for the interstitial ad. It is
// triggered when the interstitial ad is ready to play.
private void OnAdReady(object sender, object e)
{
// The ad is ready to show; show it.
interstitialAd.Show();
}
// This is an event handler for the interstitial ad. It is
// triggered when the interstitial ad is cancelled.
private void OnAdCancelled(object sender, object e)
{
}
// This is an event handler for the interstitial ad. It is
// triggered when the interstitial ad has completed playback.
private void OnAdCompleted(object sender, object e)
{
}
// This is an error handler for the interstitial ad.
private void OnAdError(object sender, AdErrorEventArgs e)
{
}
I've literarily taken this code from their UWP Store sample except that instead of launching this from a button, I'm launching it when my page is loaded:
private void Page_Loaded(object sender, RoutedEventArgs e)
{
// Request an ad. When the ad is ready to show,
// the AdReady event will fire.
// The application id and ad unit id are passed in here.
// The application id and ad unit id can be obtained from Dev
// Center.
// See "Monetize with Ads" at https://msdn.microsoft.com/
// en-us/library/windows/apps/mt170658.aspx
#if DEBUG
interstitialAd.RequestAd(AdType.Video,
"d25517cb-12d4-4699-8bdc-52040c712cab", "11389925");
#else
interstitialAd.RequestAd(AdType.Video,
"d25517cb-12d4-4699-8bdc-52040c712cab", "11389925");
#endif
}
I've left both ApplicationId and UnitAdId as the test values for the time being as I haven't released it yet, well, not with ads anyway.
Thanks
UPDATE - 2:
I've added some debugging logs in the various events and this is what I get:
Page_Loaded: 00:00:00.0001590
Page_Loaded - RequestAd: 00:00:00.0091840
OnAdReady - Elasped Time: 00:01:04.6923865
OnAdError: NetworkConnectionFailure : Media timeout occurred
during playback. - Elasped
Time: 00:00:08.1955928
It takes over 1 minute for the OnAdReady to be triggered which is really odd and then I get an OnAdError 8 seconds later so from these logs you would assume that there is a network problem but my data is being loaded correctly which is all pulled from a web service, so there is definitely a connection. Also my AdMediator displays Ads as expected (well, kind of! That's another story!).
I will try to transfer it directly to my phone tomorrow and see if it makes any differences and I plug in my laptop to an Ethernet port instead of using the wireless but my wireless is pretty decent, so I'm not sure why I'm getting network connectivity errors.
The above code is correct and does actually work with UWP on Windows Phone but it doesn't work great in the emulator as:
it intermittently generates network connectivity errors when they are none.
it can take over a minute to display the advert but it eventually will.
I've just uploaded my app to the store and downloaded it to my phone and it works as expected. It displays the advert immediately or within a couple of seconds or so.
I would recommend you do not waste too much time trying it via the phone emulator as it appears to be the main problem. Implement your code and then test it directly on your device or download it from the store assuming you haven't released your app yet.
UPDATE:
I just thought I'd update my answer as I was just reading about the do's and dont's with interstitial adverts from UI and User Experience Guidelines and the way I'm actually doing it, is one of points in the "avoid" list.
It recommends that you fetch the advert 30-60 seconds ahead of time and you don't display it when the app starts, which is what I'm doing, so I guess I will change the logic in that regards.

How to open webview in Blackberry?

How to open link in webview in Blackberry like iPhone and Android ?
Which should not be open in Browser ,it should be opening in Webview through application .
The Blackberry equivalent of a WebView is a BrowserField. Example code from this page:
import net.rim.device.api.browser.field2.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
public class BrowserFieldDemo extends UiApplication
{
public static void main(String[] args)
{
BrowserFieldDemo app = new BrowserFieldDemo();
app.enterEventDispatcher();
}
public BrowserFieldDemo()
{
pushScreen(new BrowserFieldDemoScreen());
}
}
class BrowserFieldDemoScreen extends MainScreen
{
public BrowserFieldDemoScreen()
{
BrowserFieldConfig myBrowserFieldConfig = new BrowserFieldConfig();
myBrowserFieldConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);
BrowserField browserField = new BrowserField(myBrowserFieldConfig);
add(browserField);
browserField.requestContent("http://www.blackberry.com");
}
}
Options Icon -> Host Routing Tables -> Register Now
If the above instructions failed, try stepping through these instructions one by one
* Try getting your service books retransmitted.
a. Login to your BlackBerry Web Client (BWC/BIS) site.
b. Click "Profiles" (At the top of your BWC webpage via your PC)
c. Click "Send Internet Browser Service Book"
* Try rebooting your BlackBerry by removing and reinserting battery.
* Make sure you are running BlackBerryOS 4.0 by checking:
Check Options -> About
If you are not running at least Version 4.0, you need to download and install BlackBerryOS 4.0 then repeating all the above instructions again.
* If that does not work, and you are on a BlackBerry Enterprise Server (BES), try re-activating your BlackBerry on BES. This may be as simple as connecting your BlackBerry to your PC and synchronizing your BlackBerry while Outlook is in ONLINE mode.
I think that you are looking for the BrowserField UI component.

Resources