broadcastreceiver

android - Sending a broadcast to MainActivity and then showing a TextView

[亡魂溺海] 提交于 2019-12-18 07:22:27
问题 I want to unhide a TextView once a method is called in another View file. The TextView is in MainActivity. For this, I am planning to send a broadcast from the View file to MainActivity, but it didn't work. How would I achieve this? 回答1: Step 0 : Define an action : public static final String ACTION_SHOW_TEXT= "showText"; Step 1 : Create your Broadcast receiver in your MainActivity : BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent

Starting One Android App from Another App

丶灬走出姿态 提交于 2019-12-18 07:07:19
问题 What is the best way to start one android app from another app? Is it to send custom broadcast event and have broadcast receiver of other app catch this event and do a start activity on something? Thanks 回答1: Use an Intent: http://developer.android.com/guide/topics/intents/intents-filters.html Use Context.startActivity() to just launch, or Activity.startActivityForResult() if you want to get a result when it's done. If you are tightly coupled with the other application, you can use an

Weird AlarmManager behaviour

我的梦境 提交于 2019-12-18 07:02:36
问题 I have 2 BroadcastReceivers and 2 intents, I want to click a button, 5m later start broadcast1 and 10m later start broadcast2, what's happening is they both start 10m after I click, My guess is, the intents are not unique, but I'm setting a diffrent reqeustCode for each of them. Button's OnClick: Bundle bd = new Bundle(); bd.putInt("mInt", i); Intent intent1 = new Intent(getActivity(), Broadcast_1.class); intent1.putExtras(bd); PendingIntent pendingIntent1 = PendingIntent.getBroadcast

Weird AlarmManager behaviour

白昼怎懂夜的黑 提交于 2019-12-18 07:02:24
问题 I have 2 BroadcastReceivers and 2 intents, I want to click a button, 5m later start broadcast1 and 10m later start broadcast2, what's happening is they both start 10m after I click, My guess is, the intents are not unique, but I'm setting a diffrent reqeustCode for each of them. Button's OnClick: Bundle bd = new Bundle(); bd.putInt("mInt", i); Intent intent1 = new Intent(getActivity(), Broadcast_1.class); intent1.putExtras(bd); PendingIntent pendingIntent1 = PendingIntent.getBroadcast

broadcast receiver for ACTION_CAMERA_BUTTON never gets called

一曲冷凌霜 提交于 2019-12-18 06:58:33
问题 I have an app in android in which I wanna take a photo when physical hardware button for camera gets pressed.I registered an intent for this type of action but my broadcast receiver never gets called. Here is how I did it: class that extends BroadcastReceiver public class Adisor extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT) != null) { // prevent the camera app from opening abortBroadcast();

Start application without activity, my Broadcast Receiver not work

人走茶凉 提交于 2019-12-18 06:49:47
问题 In my app, I have a Broadcast Receiver for catching the message sent to my phone <receiver android:name="com.qmobile.ows.SMS_Receiver" android:enabled="true" android:exported="true"> <intent-filter> <action android:name="android.intent.action.PHONE_STATE" /> <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </intent-filter> </receiver> If I start app with activity GUI, the BroadCast Receiver works normally. I want to start my application without activity and do not show icon

send data to email in background

元气小坏坏 提交于 2019-12-18 06:49:35
问题 I am working on sending my message data on my email Id.I have made a mainActivity class containing an editText (for emailId) and a Button. Another class is BroadcastReceiver class in which I retrieve data. Now I can't understand how to send that data to the provided email in Background. I have googled a lot but can't get the required response. Please share the ideas and help me in it. 回答1: I create open source library for this. Usage is very simple: BackgroundMail bm = new BackgroundMail

setPackage for intent in gingerbread

纵饮孤独 提交于 2019-12-18 06:48:10
问题 According to the android documentation: Alternatively, starting with ICE_CREAM_SANDWICH, you can also safely restrict the broadcast to a single application with Intent.setPackage Is there any way in Gingerbread (using the compatibility library perhaps) to restrict a sendBroadcat() event such that it only sends it to a specified package? 回答1: My first suggestion would be to use LocalBroadcastManager if at all possible. This allows you to completely ignore any security issues. If you really do

Broadcasting and receiving extra doubles

放肆的年华 提交于 2019-12-18 05:26:07
问题 I'm attempting to broadcast extras in an am broadcast in adb shell. In my BroadcastReceiver in android, I'm subscribed to the broadcast and pull the extras out of the Bundle. My trouble lies with doubles. I assumed that a broadcast could include a double since the Bundle class has a getDouble method, e.g.: double percentComplete = bundle.getDouble("percent_complete"); However, the am broadcast command in adb shell doesn't seem to support doubles, only floats. When I send the float, the Bundle

Intent PACKAGE_ADDED not registering

拈花ヽ惹草 提交于 2019-12-18 05:22:27
问题 Hello i am trying to detect application installed so that i can do some analysis on the application and i am using this example i found on stackoverflow to listen for package installs from my current application but nothing is happening in my logcat. void registerReceiver() { IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); filter.addAction(Intent.ACTION_PACKAGE_REMOVED); filter.addAction(Intent.ACTION_PACKAGE_CHANGED); filter.addDataScheme("package"); } public void