i am developing an application, when the app is open there may be any missed call the notification is displayed,how i hide or remove the notification bar & is there any way to implement it.
i have put all codes like below in my application,
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
and
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen"
but i open an activity file using broadcast receiver, then the notification is seen when missed call or message arrives
You can use this code:
public class FullScreen
extends android.app.Activity
{
#Override
public void onCreate(android.os.Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}
I was having the exact same problem as yours, but I hade it for both incoming and outgoing calls. I found the solution for the incoming calls/ missed calls but not yet for the outgoing calls.
What you are going to do is the following: 1.Create a BroadCastReceiver Class to listen to incoming calls with the highest priority:
a.In the Manifest.xml add:
<receiver android:name=".MyPhoneBroadcastReceiver">
<intent-filter android:priority="99999">
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
b.Then the Class
#Override
public void onReceive(final Context context, Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null) {
String state = extras.getString(TelephonyManager.EXTRA_STATE);
final String incomingNumber = extras.getString("incoming_number");
Handler callActionHandler = new Handler();
Runnable runRingingActivity = new Runnable(){
#Override
public void run() {
//Notice the intent, cos u will add intent filter for your class(CustomCallsReceiver)
Intent intentPhoneCall = new Intent("android.intent.action.ANSWER");
intentPhoneCall.putExtra("INCOMING_NUM", incomingNumber);
intentPhoneCall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intentPhoneCall);
}
};
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
//increase the delay amount if problem occur something like -the screen didn't show up- that's the key about this method(the delay).
callActionHandler.postDelayed(runRingingActivity, 100);
}
if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
callActionHandler.removeCallbacks(runRingingActivity);
}
}
}
2.a.In the Manifest.xml file add this intent filter for the class you will use as a custome call receiver.
<activity android:name="CustomCallsReceiver" android:noHistory="true" android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.ANSWER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
2.b.The CustomeCallsReceiver Class:
public class CustomCallsReceiver extends Activity {
private String TAG = "CustomCallsReceiver";
String incomingNumber, caller;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custome_calls_receiver);
TextView number = (TextView) findViewById(R.id.number);
number.setGravity(Gravity.CENTER);
incomingNumber = getIntent().getExtras().getString("INCOMING_NUM");
caller = getCallerName(incomingNumber);
if (caller != null) {
number.setText(caller + "\n" + incomingNumber); } }
3.And finally of course don't forget to add the Theme for not title or notification bar at the Manifest.XML file
<application
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
You need to set the theme in Android manifest .xml.. .
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen"
Hope this will help you..
if you set this as application theme it will give effect all the pages of your app..
<application
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
>
Related
I'm currently trying to implement mollie payment into the flutter framework. For that I want to build a plugin in Java. So mollie has a very good documentation how to implement their API into an android app with Java. So the problem is when I hit the payment button in my app the browser opens with the correct checkout page. After the customer select his preferred payment method mollie goes back to my app, but I always get a empty query...
So this is my code for the flutter plugin
public class MolliePlugin implements MethodCallHandler, PluginRegistry.ActivityResultListener {
Activity activity;
Result activeResult;
Context context;
Intent intent;
boolean getData;
private static final int REQUEST_CODE = 0x1337;
MolliePlugin(Registrar registrar){
activity = registrar.activity();
}
/** Plugin registration. */
public static void registerWith(Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), "mollie");
channel.setMethodCallHandler(new MolliePlugin(registrar));
}
#Override
public void onMethodCall(MethodCall call, Result result) {
if (call.method.equals("startPayment")) {
activeResult = result;
String checkout = call.argument("checkoutUrl");
startPayment(checkout);
}
else {
result.notImplemented();
}
}
/// Start the browser switch with a ACTION_VIEW
void startPayment(String checkoutUrl) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW,Uri.parse(checkoutUrl));
activity.startActivity(browserIntent);
}
So in the docs of mollie is written that I have to put the following code into the onCreate() function in my MainActivity:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//...
Intent intent = getIntent();
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
Uri uri = intent.getData();
String paymentId = uri.getQueryParameter("id");
// Optional: Do stuff with the payment ID
}
}
So when I put this into the onCreate() in my MainActivity of my Flutter app I get always an ACTION_RUN back after I was routed back to my app. So I used the onNewIntent() function which gives me the correct action after coming back to my app (any ideas why?):
public class MainActivity extends FlutterActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.d("Action is: ",intent.getAction());
String paymentId = "No Id";
if (Intent.ACTION_VIEW.equals(intent.getAction()) && intent != null) {
Uri uri = intent.getData();
// This has no data...
Log.d("query ",intent.getDataString());
paymentId = uri.getQueryParameter("id");
// Optional: Do stuff with the payment ID
}
}
}
So here I get an empty query. the intent.getData() only returns my returnUrl which I have to set up in my AndroidManifest (see below). The returnUrl works fine but it has no data included after checking out and swichting back to the app...
My AndroidManifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.plugon.mollie_example">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="mollie_example"
android:icon="#mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in #style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<data
android:host="payment-return"
android:scheme="molli" />
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
</application>
</manifest>
Any ideas what I'm doing wrong?
The function "onReceive" is called when BroadcastReceiver is Registered in the Manifest but NOT called if registered dynamically.
The code that works is below:
public class EyeGesture extends BroadcastReceiver {
//Eye Gesture
private static IntentFilter eyeGestureIntent;
private static Context eyeGestureContext;
private static StringBuilder gestureInfo = null;
private static BroadcastReceiver broadcastReceiver;
// public void startEyeListening() {
//Eye Gesture
//}
#Override
public void onReceive(Context context, Intent intent) {
// this = context;
if (intent.getStringExtra("gesture").equals("WINK")) {
Log.e("WINKED ","");
}else {
Log.e("SOMETHING", "is detected " + intent.getStringExtra("gesture"));
}
//Disable Camera Snapshot
// abortBroadcast();
}
public void stopEyeListening() {
eyeGestureContext.unregisterReceiver(broadcastReceiver);
eyeGestureIntent = null;
eyeGestureContext = null;
gestureInfo = null;
}
}
Below is the Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.inno.inno.glassplugin" >
<uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainFunct"
android:icon="#drawable/ic_glass_logo"
android:label="#string/title_activity_main_funct" >
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="#xml/voice_trigger" />
</activity>
<receiver android:name="com.inno.inno.glassplugin.EyeGesture">
<intent-filter>
<action android:name="com.google.android.glass.action.EYE_GESTURE" />
</intent-filter>
</receiver>
</application>
</manifest>
The problem is that "onReceive" is NOT called when registered dynamically. I have to do this in a dynamic way.
Below is the code that is NOT working code.
public class EyeGesture extends Activity {
//Eye Gesture
IntentFilter eyeGestureIntentFilter;
Context eyeGestureContext;
BroadcastReceiver broadcastReceiver;
public EyeGesture(){
Log.e("CONSTRUCTOR ", "");
eyeGestureContext = MainFunct.getCurrentContext();
eyeGestureIntentFilter = new IntentFilter("com.google.glass.action.EYE_GESTURE");
eyeGestureIntentFilter.setPriority(1000);
startRunning();
}
void startRunning(){
eyeGestureContext.registerReceiver(new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
Log.e("Received ", " Something");
}
},eyeGestureIntentFilter);
}
#Override
public void onResume(){
super.onResume();
}
#Override
public void onPause(){
super.onPause();
unregisterReceiver(broadcastReceiver);
}
public void stopEyeListening() {
eyeGestureContext.unregisterReceiver(broadcastReceiver);
eyeGestureIntentFilter = null;
eyeGestureContext = null;
}
}
Also, I don't want to extend BroadcastReceiver from this class. Why am I not receiving anything if registered dynamically. I also removed the following line from the Manifest:
<receiver android:name="com.inno.inno.glassplugin.EyeGesture">
<intent-filter>
<action android:name="com.google.android.glass.action.EYE_GESTURE" />
</intent-filter>
</receiver>
but still, it is not working. There is no error or exception thrown.
What am I doing wrong?
Are you using explicit intent? It seems that dynamically registered broadcast receivers cannot receive explicit intents. Implicit intents work.
For reference: http://streamingcon.blogspot.com/2014/04/dynamic-broadcastreceiver-registration.html
If the issue is not explicit intents but if you are using LocalBroadcastManager for sendBroadcast then make sure that the registerReceiver is also called of LocalBroadcastManager and not of Context
Try using ApplicationContext instead of Activity.
Modyifing line:
eyeGestureContext = MainFunct.getCurrentContext();
I would try things in this order:
eyeGestureContext = getApplicationContext();
eyeGestureContext = getApplication();
If above does not work I would extend the Application and do:
public class MyExtendedApplication extends Application {
private static MyExtendedApplication instance;
public static MyExtendedApplication getInstance() {
return instance;
}
}
This works for me with global "android.net.conn.CONNECTIVITY_CHANGE" broadcast
Context c = MyExtendedApplication.getInstance();
c.registerReceiver(
connectivtyChangedReceiver,
connectivityFilter);
so should also for you with "com.google.android.glass.action.EYE_GESTURE"
Watching adb logcat in XE21.3, it looks like com.google.android.glass.action.EYE_GESTURE intent never hits the event bus; instead, it skips straight to com.google.glass.action.TAKE_PICTURE, which is the same intent as the camera button. So it looks like the eye-gesture API was removed without announcement.
The receiver should extend the BroadcastReceiver class.
Define the receiver in the manifest
In the code (maybe onCreate), register the receiver
Create a receiver object
Define the intent filters
call RegisterReceiver() passing in the receiver and the intent filters
When phone state is ringing, I want to run an activity to show my own screen.
I'm using:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
and
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
but notification bar does not hide when activity is shown.
Go through following code snippets:
Create a BroadCastReceiver Class to listen to incoming calls with
the highest priority:
Manifest.xml:
<receiver android:name=".MyPhoneBroadcastReceiver">
<intent-filter android:priority="99999">
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
Then in class, onReceive() method opens the CustomCallsReceiver Activity with intent action is "android.intent.action.ANSWER"
#Override
public void onReceive(final Context context, Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null) {
String state = extras.getString(TelephonyManager.EXTRA_STATE);
final String incomingNumber = extras.getString("incoming_number");
Handler callActionHandler = new Handler();
Runnable runRingingActivity = new Runnable(){
#Override
public void run() {
//Notice the intent, cos u will add intent filter for your class(CustomCallsReceiver)
Intent intentPhoneCall = new Intent("android.intent.action.ANSWER");
intentPhoneCall.putExtra("INCOMING_NUM", incomingNumber);
intentPhoneCall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intentPhoneCall);
}
};
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
//increase the delay amount if problem occur something like -the screen didn't show up- that's the key about this method(the delay).
callActionHandler.postDelayed(runRingingActivity, 100);
}
if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
callActionHandler.removeCallbacks(runRingingActivity);
}
}
}
Add this intent filter in to manifest file for the class you will
use as a Custom call receiver.
<activity android:name="CustomCallsReceiver" android:noHistory="true" android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.ANSWER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
The CustomeCallsReceiver Class:
public class CustomCallsReceiver extends Activity {
private String TAG = "CustomCallsReceiver";
String incomingNumber, caller;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custome_calls_receiver);
TextView number = (TextView) findViewById(R.id.number);
number.setGravity(Gravity.CENTER);
incomingNumber = getIntent().getExtras().getString("INCOMING_NUM");
caller = getCallerName(incomingNumber);
if (caller != null) {
number.setText(caller + "\n" + incomingNumber); }
}
And finally of course don't forget to add the Theme for not title or
notification bar at the manifest file
<application
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
Hope this working for you...
My broadcast receiver is Still getting execute even if My application is not working.
as an example I am using android.intent.action.NEW_OUTGOING_CALL to check outgoing call and than i stop music and push notification ..
but even i close my app and kill all task and after if i call than i get notification of my app..
So how do i manage to work my broadcast when i am using my app.
I have crated Service to play music and 2 broadcast receiver file for incoming and outgoing.
Help to solve this problem.
Also How can i destroy my app with service running behind If user press exit button.
**Update I made edited it and its working now fine..thank you so much you all
here is my code
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="OutgoingCallInterceptor">
<intent-filter android:priority="1">
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
<receiver android:name="IncomingCallInterceptor">
<intent-filter android:priority="1">
<action android:name="android.intent.action.PHONE_STATE" />
<action android:name="android.media.AUDIO_BECOMING_NOISY" />
</intent-filter>
</receiver>
Update
as you all suggest me i have made receiver into main class file and register it from there but it wont work
public class MainActivity extends Activity {
RemoteViews layout;
int SDK_INT;
BroadcastReceiver br;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
IntentFilter filter = new IntentFilter("android.media.AUDIO_BECOMING_NOISY");
this.registerReceiver(br, filter);
setContentView(R.layout.activity_main);
SDK_INT = android.os.Build.VERSION.SDK_INT;
System.out.println(SDK_INT);
Button start = (Button)findViewById(R.id.play);
Button stop = (Button)findViewById(R.id.stop);
start.setOnClickListener(startListener);
stop.setOnClickListener(stopListener);
br = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent.getAction().equals(android.media.AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {
context.stopService(new Intent(context, myPlayService.class));
Toast.makeText(context, "Headphones disconnected.", Toast.LENGTH_SHORT).show();
}
} }
};
#Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(br);
}
an example: how a broadcast reciver can be registered and un registered change as per your need "i hope the code is self explanatory"
private final BroadcastReceiver xyz= new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
//ur reciver
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
IntentFilter filter = new IntentFilter(ACTION);//ur action
this.registerReceiver(xyz, filter);
}
#Override
protected void onDestroy(){
super.onDestroy();
unregisterReceiver(xyz);
}
You need to declare unregisterReceiver() in onResume() or in onpause() methods.
This will solve your problem.
First:
use unregisterReceiver() in onPause() and re-register in onStart().
It's always better to have locally registering the receiver if you want to provide the functionality only when your app is up.
Second:
Use service after binding it and don't call unBind while exiting the app will keep your service alive even after your app is down. I guess you are starting the service locally. Start service by binding it.
Hope this will solve your problem.
I have spent the last couple of hours looking through other questions on this topic and none that I found were able to give me any answers.
What is the best way to pass a string from an activity to a broadcast receiver in the background?
Here is my main activity
public class AppActivity extends DroidGap {
SmsReceiver mSmsReceiver = new SmsReceiver();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ScrollView scroll;
scroll = new ScrollView(this);
Bundle bundle = getIntent().getExtras();
final String ownAddress = bundle.getString("variable");
registerReceiver(mSmsReceiver, new IntentFilter("MyReceiver"));
Intent intent = new Intent("MyReceiver");
intent.putExtra("passAddress", ownAddress);
sendBroadcast(intent);
Log.v("Example", "ownAddress: " + ownAddress);
}
}
Here is my broadcast receiver
public class AppReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
final String ownAddress = intent.getStringExtra("passAddress");
Toast test = Toast.makeText(context,""+ownAddress,Toast.LENGTH_LONG);
test.show();
Log.v("Example", "ownAddress: " + ownAddress);
}
}
Here is the manifest for my receiver
<service android:name=".MyService" android:enabled="true"/>
<receiver android:name="AppReceiver">
<intent-filter android:priority="2147483647">
<action android:name="android.provider.Telephony.SMS_SENT"/>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<receiver>
<service android:name=".MyServiceSentReceived" android:enabled="true"/>
<receiver android:name="AppReceiver">
<intent-filter android:priority="2147483645">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
When the broadcast receiver logs an event the app crashes. I need to have it run behind the scenes and pull a string from my main activity.
Can anyone help me with this or point me in the right direction?
Addition from comments and chat
Your String ownAddress will always be null unless the Intent has an String with the key passAddress in the the Bundle extras. Anytime your Receiver catches an Intent (whether from SMS_SENT, SMS_RECEIVED, or BOOT_COMPLETED) ownAddress will be null because the OS doesn't provide a String extra named passAddress. Hope that clears things up.
Original Answer
I haven't used DroidGap but this is what you want for a regular Android Activity.
Activity:
public class AppActivity extends Activity {
AppReceiver mAppReceiver = new AppReceiver();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerReceiver(mAppReceiver, new IntentFilter("MyReceiver"));
String string = "Pass me.";
Intent intent = new Intent("MyReceiver");
intent.putExtra("string", string);
sendBroadcast(intent);
}
}
Receiver:
public class AppReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, intent.getStringExtra("string"), Toast.LENGTH_LONG).show();
}
}
Don't forget to unregister the receiver in onDestroy(), like this:
#Override
protected void onDestroy() {
unregisterReceiver(mAppReceiver);
super.onDestroy();
}