I want to make a simple service, (which will run in the background) when any user copies anything from the browser or sms etc., there will be a toast showing that text
I have this code which gives toast when there is a phone call
public class MyPhoneReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null) {
// this code is for to accept the telephone call
String state = extras.getString(TelephonyManager.EXTRA_STATE);
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
String phoneNumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
Toast.makeText(context, phoneNumber, Toast.LENGTH_SHORT).show();
}
}
}
}
and this code in manifest.xml
<action android:name="android.intent.action.PHONE_STATE"></action>
now this code tell to send any phone state to the myreciever class now I want to get text from clipboard manager. is there any intent.action state which can call myreciever class when someone copies text.
Any kind of help or code will be appreciated.
Since there is now Action intent for clipboard, what you will need to do is create a broadcast receiver to start when your app is started on when the device first boots up. And then start a service to monitor the state of the clipboard.
This is a PERFECT project on google code that will show you EXACTLY what to do.
My Clip tutorial
I'm agree with "coder_For_Life22":"Since there is now Action intent for clipboard, ...".
I found two ways for monitoring "clipboard":
1-A way like what says "coder_For_Life22".
2-Using "ClipboardManager.OnPrimaryClipChangedListener()" method.
But both of them have issues :
In first way if user copy a word for example "Text" and then (even after sometimes and in another App) again copy the same word,you can not detect it.
Second way, is a solution for using android 3.0 api 11 and not lower.
Related
I am working with a bluetooth button and Zebra TC20. I want to start zebra's scan when extra bluetooth button get clicked.
Bluetooth button is supported by their app - flic. There is an option to send Intent. So I would like to send intent to my app. This could be done by implicit intent. But I am building this app so I know exact activity when the scan should be triggered.
From what I read I should use explicit intent if I want the activity which I know the name, but everywhere explicit intent is tied within one app.
Is it possible to call specific activity of my app from another app?
This question is edited.
Look at the manual at page 52-61 everything is explained, i had to implement it with a ET55, but it seems to be the same process.
I personnaly did it using the Intent output option ith intent delivered via broadcast.
First you can make open the DataWedge App (the app should be preinstalled, it is where you configure things about the scanner)
You create a profile for your app
You click on the profile and you check the Profile enabled option
You enable barcode input and Intent ouput, disable Keystroke and ip output
You associate your app (Associated apps option)
(go to Page 75-76 of manual) You set the intent action with something like datawedge.yourapp.SCANNER_RESULT
You left category blank
You set intent delivery to Broadcast Intent
For the rest the default option should be ok
Then, in your app you have to register the broadcast receiver (in onCreate()):
//first you implement the action to be executed when it receives the broadcast
receiverZebra = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
final String scanResult = intent.getStringExtra("com.symbol.datawedge.data_string");
/*
do things with the barcode here
*/
}
};
//then make a filter for the broadcast
filterZebra = new IntentFilter();
filterZebra.addCategory(Intent.CATEGORY_DEFAULT);
//the action you set in step 5 in datawedge
filterZebra.addAction("datawedge.yourapp.SCANNER_RESULT");
Then in the onStart and onStop methods you can register/unregister your broadcast receiver
#Override
protected void onStart(){
super.onStart();
registerReceiver(receiverZebra, filterZebra);
}
#Override
protected void onStop()
{
super.onStop();
unregisterReceiver(receiverZebra);
}
There are other ways to implement it, there wouldn't be other option than Intent output if there were not but it works great for me. I don't think there is much differences between the TC20 and ET55 so it should work for you as well
After the question was edited
Taken from this tutorial
In the configuration app of your button, you should be able to link an intent action name to the bluetooth button. To receive it, you have to set an intent filter in your app manifest :
<activity
android:name="com.example.myapplication.activitytolaunch"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.myapplication.ACTIVITY_TO_LAUNCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
And your button will have to launch the intent : "com.example.myapplication.ACTIVITY_TO_LAUNCH"
If you want to launch the activity directly, you can use the second part of the answer. If you have to process the barcodes when your app is opened (i.e. adding the barcodes to a list), if you can tell the button to broadcast an intent, you can use the first part.
I have an issue that I have not found a solution to on this site, but if this is a duplicate question, I apologize.
I am developing an application that serves as a terminal for registering when employees start/finish work, among numerous other things. The way it works is that with NFC switched-on, they scan their NFC cards and my app reads them and ultimately sends the appropriate information to the server.
However, if the app is already open (it's supposed to be open all the time, so this is an issue) and an NFC card is scanned, it reopens the app. Of course, this is done because I have set it that way in the manifest. But I can not find a way to have my app recieve the NFC scan intent if I do not add all of these lines in the manifest:
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
I have tried just writing without the but in that case it does not read the card, but instead the program chooser comes up on the phone, or if the phone does not have an appropriate app it simply says "NFC read error".
Does anyone have a solution for this? This is the last step in my project, and I have had a lot of trouble with it, and would appreciate any help. It's probably something simple that I'm just not seeing, but I'd appreciate it either way.
Android activities have different launch modes. If you set single instance it will use already opened activity and doesn't create a new activity. You can read the new intent in override method onNewIntent()
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// read intent values here
}
For various activity elements
You can use broadcastReceiver,
- first initiate the receiver to your activity
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("whateveryouwant");
notificationBroadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
// here you can read the intent and customize the action;
int usage = intent.getIntExtra("usage",1000);
}
}
};
second register the broadcast
registerReceiver(notificationBroadcastReceiver,intentFilter);
At end unregister to the broadcast in the onDestroy method
#Override
protected void onDestroy() {
if(notificationBroadcastReceiver != null){
unregisterReceiver(notificationBroadcastReceiver);
notificationBroadcastReceiver = null;
}
super.onDestroy();
}
after doing that instead of intenting activity you can sendBroadcast()
a little guide: https://developer.android.com/reference/android/content/BroadcastReceiver.html
hope it will be helpfull
I have this code for checking app uninstall:
public void onReceive(Context context, Intent intent){
final String action = intent.getAction();
if("android.intent.action.PACKAGE_REMOVED".equals(action)){
// some action
}
Now I want get the start intent from the uninstalled app.
Is it possible?
Refer to following URLs:
Perform a task on uninstall in android
How to show an Activity BEFORE my app is uninstalled (Android)
The Post by Janusz is very helpful here..
Sadly android at the moment does not give you a possibility to perform code at the moment your app is uninstalled.
All the settings that are set via the SharedPreferences are deleted together with everything in the Aplication Data an Cache folder.
The only thing that will persist is the data that is written to the SD-Card and any changes to phone settings that are made. I don't know what happens to data that is synchronized to the contacts through your app.
I guess the only way to discover this is to test this. You can use the following code to find the launch intent of an application:
final Intent launchIntent = pm.getLaunchIntentForPackage(packageName);
where pm - is PackageManager.
To my point of view this is impossible and you'll receive launchIntent equal to null. But you should check this on your own.
Iam new to android. I could understand the concept of Broadcast Receivers, but i couldn't understand the concept of sendBroadcast(Intent i).. My main doubt is who will listen to this sendBroadcast.
public class OOVOOActivity extends Activity {
/** Called when the activity is first created. */
public static int count = 0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
addShortcut();
}
private void addShortcut(){
Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
// Shortcut name
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
shortcut.putExtra("duplicate", false); // Just create once
// Setup current activity shoud be shortcut object
ComponentName comp = new ComponentName(this.getPackageName(), "."+this.getLocalClassName());
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
// Set shortcut icon
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.search);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
sendBroadcast(shortcut);
}
I have few questions to ask,
In the above code there is no toast message is used, But if i
run the app i could see the toast msg.. Plz explain how it is coming
and also tell me how to hide those toast msg.
U could see sendBroadcast(shortcut); , basically who will listen to this broadcast.
Plz clear my doubt. Thank U
U could see sendBroadcast(shortcut); , basically who will listen to this broadcast.
Some other app or apps. No app might receive this broadcast. 999 apps might receive this broadcast. That is up to the user and the developers of those other apps.
In this case, you are assuming that there are one or more apps on the device that will respond to a com.android.launcher.action.INSTALL_SHORTCUT broadcast. Please note the com.android. This means that this Intent action is not part of the Android SDK. com.android is used for pieces of the Android environment. As it turns out, this Intent action is not documented, meaning that it may or may not work on all devices and Android OS versions.
Plz explain how it is coming
Other developers, besides you, can write code that displays Toast messages. They can even write code that displays Toast messages in response to a broadcast Intent. It turns out that your test environment contains such code, possibly in the com.android.launcher application.
also tell me how to hide those toast msg
You don't.
In my application I have apply new outgoing call receiver. It is working fine. I get whenever new outgoing call is made.
But now, in my device there are two applications for dial call. First is default dialer and second is my own dialer (Using Call_Privilage).
My question is: when I got broadcast for new dial in my receiver at that time how can I know that from which dialer application call is dialed. From default dialer or my own dialer?
I have not implemented this and tested but I assume like this will work for you.
In your own dialer Activity whenever you are calling intent to make a call,
at that time you should pass one more putExtra with that callIntent
For Ex : callIntent.putExtra("fromMyDialer",1);
Now in your Receiver file, you will be having one method like this below and there you will just need to have check for the extra we passed above.
#Override
public void onReceive(final Context context, final Intent intent) {
if(intent.getIntExtra("fromMyDialer",0)==1)
// from my own dialer activity
else
// from default dialor of phone
}