I want my application to be activated when the user make a specific call. Is there any way to take information which call is making by user in the same time ( not afterwords ) in order to activate the app at the right time ?
Ok i wrote this code for my case and it works:
public class OutgoingCallReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if(null == bundle) return;
String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
if( phonenumber.equals("11111111") ) {
Intent myactivity = new Intent(context, MyKeyboard.class);
myactivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myactivity);
}
}
}
In the Manifest i add this:
<receiver
android:name=".OutgoingCallReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
I don't really know, but I think that's a really dangerous practice. It all depends on what you intend to do with your app. If it's a recording app, I think you can't even think of developping it, or don't post on the internet about it because it would be illegal in many countries. That's how I see and how I feel your question. About Android there is not 15k places to search, have a look at the android API.
http://developer.android.com/reference/android/provider/CallLog.Calls.html
This, for example, I don't know if it's a real time log, or if it's filled after the call is terminated. But you can search in that direction.
Related
I'm composing a Tweet and then launch Twitter app to tweet it like that:
intent = new TweetComposer.Builder(getFragmentActivity())
.text(viewHolder.etShareText.getText().toString())
.url(contentUrl)
.image(imageUri)
.createIntent();
It worked for a long time, and it still works, I'm able to post a tweet to my profile, but some time ago every action was resulted with RESULT_CANCELED in my onActivityResult() method despite the actual result was successfull.
Maybe something had changed in Twitter API? How to handle results now?
Actually, in this case onActivityResult() usage may not true way. To catch composing result, like vijikumar said, we should use BroadcastReceiver. But this information is not enough for us. Because in many cases, twitter composing ways are confused with each other. Like documentation said ; there are two ways to compose tweets :
Launch the Twitter application’s Tweet Composer
Launch the Twitter Kit Native Composer
If you prefer to use first way, as long as i see, there is not a healthy method to catch composing result using BroadcastReceiver, onActivityResult or etc.
BroadcastReceiver method does not work using first way. But if you prefer to use second way, you can catch composing result using BroadcastReceiver in a healthy position. You shouldn't think that first way is not important. I am going to talk about first way briefly.
To do these above ;
Second Way
Add below repository and dependencies in your app level gradle file
repositories {
jcenter()
}
compile 'com.twitter.sdk.android:twitter-core:3.1.1'
compile 'com.twitter.sdk.android:tweet-composer:3.1.1'
Then add below BroadcastReceiver
public class MyResultReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (TweetUploadService.UPLOAD_SUCCESS.equals(intent.getAction())) {
// success
} else if (TweetUploadService.UPLOAD_FAILURE.equals(intent.getAction())) {
// failure
} else if (TweetUploadService.TWEET_COMPOSE_CANCEL.equals(intent.getAction())) {
// cancel
}
}
}
Then add your BroadcastReceiver to the application manifest file like below
<receiver
android:name=".MyResultReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.twitter.sdk.android.tweetcomposer.UPLOAD_SUCCESS"/>
<action android:name="com.twitter.sdk.android.tweetcomposer.UPLOAD_FAILURE"/>
<action android:name="com.twitter.sdk.android.tweetcomposer.TWEET_COMPOSE_CANCEL"/>
</intent-filter>
</receiver>
As last, to open the composer screen, start ComposerActivity using below code block
final TwitterSession session = TwitterCore.getInstance().getSessionManager()
.getActiveSession();
final Intent intent = new ComposerActivity.Builder(YourActivity.this)
.session(session)
.text("Love where you work")
.hashtags("#twitter")
.createIntent();
startActivity(intent);
When you use this way, you will catch composer result in BroadcastReceiver.
I will not share any code block about First Way. But why can we need the first way ? Actually first way contains very rich content but as long as i see, it does not support to catch result. So second way is enough for us in many cases. however if Twitter app does not exist the device, second way will crash because of session. In this case, we should use first way to open composer screen in internet browser. So we should use both ways but like you see that first one is more effective than second one.
NOTE : Do not forget to add the twitter kit initialization configurations and authentication mechanisms please.
Use BroadcastReceiver.
public class MyResultReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (TweetUploadService.UPLOAD_SUCCESS.equals(intent.getAction())) {
// success
final Long tweetId = intentExtras.getLong(TweetUploadService.EXTRA_TWEET_ID);
} else {
// failure
final Intent retryIntent = intentExtras.getParcelable(TweetUploadService.EXTRA_RETRY_INTENT);
}
}
}
In manifest
<receiver
android:name=".MyResultReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.twitter.sdk.android.tweetcomposer.UPLOAD_SUCCESS"/>
<action android:name="com.twitter.sdk.android.tweetcomposer.UPLOAD_FAILURE"/>
</intent-filter>
</receiver>
We can hide the android app from launcher by editing manifest XML,but is there any code snippet or example by which we can hide the app and start it by entering some code like ##4444## like that.Any way to do this??
Thanks in advance.
To start your app from dialer you need to do three things:
1. Add receiver to your AdroidManifest.xml
<receiver android:name="com.example.HiddedReceiver">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver>
2. Create BroadcastReceiver as stated in xml. It will intercept EVERY calls number. You just need to scan it for your string and do apropiate action - in this case fire off an intent.
public class HiddenReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(android.intent.action.NEW_OUTGOING_CALL)) {
String resultData = getResultData();
if (resultData != null) {
if (resultData.contains("YOURCODE")) {
setResultData(null); // it wont continue calling that number
//HERE CREATE your intent
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
}
}
}
3. To get this working, you need to tell android you will be using this feature, and to grant permission to process calls from the user at install time.
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
i didnt test it, but this one works like a charm:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
I develop one apps mobile number lock, i want whenever mobile on,or restart or switch on ,or on from the top/left/right button placed on mobile in short whenever mobile screen on my lock activity call, i have no idea to how to call activity at time of mobile on please any one give some related example to start activity at first when mobile on. so my lock dispay to user and then enter number password and lock open ...thanks in advance..
Following is working for me :
enter code here :
public class BootReciever extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() != null) {
if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
Intent s = new Intent(context,ViewPagerMainActivity.class);
s.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(s);
}
}
}
}
and in menifist file add follwing:
enter code here :
<receiver android:name=".BootReciever">
<intent-filter android:enabled="true" android:exported="true">
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
There are multiple ways, to achieve this. One way is you can go through Broadcasting a message for your app, after the boot of your mobile. Try reading:
http://developer.android.com/reference/android/content/BroadcastReceiver.html
Also have look at this thread, this will solve your problem.
How to launch activity on BroadcastReceiver when boot complete on Android
I'm trying to add to my app a referral tracking system so I would be able to know who of my affiliates partner sent the user to download my program. I've encounter several websites who write about it but still failed to understand some issues.
I've added this to my menifest
<receiver android:name="com.cool.PlayStoreReferralReceiver" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
and created this object:
public class PlayStoreReferralReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null) {
String referrerString = extras.getString("referrer");
Log.d("DEBUG", "Set Value:"+referrerString);
}
}
}
It seems to be working fine but I have 2 questions
I dont understand why I need to build a link which look like that for example:
https://play.google.com/store/apps/details?id=com.joelapenna.foursquared&referrer=utm_source%3Dtooyoou%26utm_medium%3Dbanner%26utm_term%3Dfoursquare%26utm_content%3Dfoursquare-tooyoou%26utm_campaign%3Dfoursquare-android
and not do it my way like that:
https://play.google.com/store/apps/details?id=com.joelapenna.foursquared&referrer=affiliate1
I've been checking it with the program 'Referral Tester' and it seems to work is that safe enough to relay on ?
Thanks so much,
Or.
For those who need to know:
Referral Tester working great.
you can get the referral like that : https://play.google.com/store/apps/details?id=com.joelapenna.foursquared&referrer=affiliate1 or basicly anything after the referrer parameter
I have a few intents that activity sends to service.
All of those are registered in manifest:
<service android:name=".location.LocationService" android:label="#string/location_service_started">
<intent-filter>
<action android:name="#string/location_service_set" />
<action android:name="#string/location_service_start" />
<action android:name="#string/location_service_stop" />
</intent-filter>
</service>
But only location_service_start and location_service_stop intents are received. What could be the reason?
There is my receiver code:
private BroadcastReceiver LocationServiceReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(getString(R.string.location_service_stop)))
{
showMessage("stop");
}
if(intent.getAction().equals(getString(R.string.location_service_start)))
{
showMessage("start");
}
if(intent.getAction().equals(getString(R.string.location_service_set)))
{
showAlertBox("set");
}
}
};
So I never see "set" message. I've even tried put sendBroadcast for "start" and "set" messages in the same place, but everything still the same. "start" - OK, "set" - never received.
Functions that fires intents:
protected void start()
{
Intent intent = new Intent(getString(R.string.location_service_start));
getApplicationContext().sendBroadcast(intent);
}
protected void set(double lat, double lon, double rad)
{
Intent intent = new Intent(getString(R.string.location_service_set));
intent.putExtra("lat", lat);
intent.putExtra("lon", lon);
intent.putExtra("rad", rad);
getApplicationContext().sendBroadcast(intent);
}
Both are correct send, without errors, actions are correct.
UPD:
Oh, my fault. I forgot to add filter.addAction... for new intent.
I'm sorry. But answers was really useful! Thank you!
All of those are registered in manifest:
Generally, you do not use string resources for action strings in an <intent-filter>, because you never want to internationalize them.
Generally, you do not use an <intent-filter> at all with a service unless you are exposing that service to third-party apps. In fact, right now, you are exposing your service to third-party apps, so anyone can send these commands to your service.
But only location_service_start and location_service_stop intents are received
No, none of them are received by the service. You are sending broadcasts in the Java code. Services do not receive broadcasts.
Functions that fires intents:
Do not use getApplicationContext() unless you know what you are doing. Whatever you are calling getApplicationContext() on is a Context, so you can just call sendBroadcast() on it.
Copy & Paste from this question I just answered. Should be the same issue.
You have to put each <action /> tag inside a seperate <intent-filter /> tag in your manifest.
This should be a bug, since the doc states you can put more than one action inside a filter tag:
Zero or more action [..] tags should be included
inside to describe the contents of the filter.
Source