This my Androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.abc.testapp"
android:versionCode="1"
android:versionName="Pm61" >
<uses-sdk android:minSdkVersion="15"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<supports-screens android:anyDensity="true" />
<application android:label="#string/app_name" android:debuggable="true" android:largeHeap="true">
<activity android:name="com.abc.testapp.MainClass" android:label="#string/app_name" android:theme="#android:style/Theme.Translucent" android:hardwareAccelerated="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
.
.
.
.
.
.
<activity android:name="com.abc.testapp.BootLoad"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" >
</activity>
<activity android:name="com.abc.testapp.Rxmain" android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" android:launchMode="singleTask">
</activity>
<receiver android:name="com.abc.testapp.MyReceiver" android:enabled="true">
<intent-filter android:priority="500">
<action android:name= "android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.MEDIA_MOUNTED"/>
<data android:scheme="file" />
</intent-filter>
</receiver>
</application>
</manifest>
This is my MyReceiver class for broadcasting
package com.abc.testapp;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class MyReceiver extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
if(Intent.ACTION_MEDIA_MOUNTED.equals(action))
{
Log.d("MYReceiver","Mounting Successfull");
Intent serviceActivity = new Intent(context, Rxmain.class);
serviceActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(serviceActivity);
}
if(Intent.ACTION_BOOT_COMPLETED.equals(action))
{
Log.d("MYReceiver","Boot Successfull");
Intent serviceActivity = new Intent(context, BootLoad.class);
serviceActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(serviceActivity);
}
}
}
My device is stand alone device, only my app will come on boot.
I want when boot complete it shall launch BootLoad activity and after MEDIA_MOUNTED it should launch Rxmain Activity.
But my bootLoad activity is not coming
So I have some doubts in this:
It is working sometimes but sometimes not?
2.what is this Priority in Intent-filter?
what this data scheme does?
what I am doing is correct or not?
please suggest me
The problem is the way you've defined the intent filter for the broadcast receiver. This is your definition:
<receiver android:name="com.abc.testapp.MyReceiver" android:enabled="true">
<intent-filter android:priority="500">
<action android:name= "android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.MEDIA_MOUNTED"/>
<data android:scheme="file" />
</intent-filter>
</receiver>
You've defined a single intent filter that will be triggered if the ACTION is either BOOT_COMPLETED or MEDIA_MOUNTED. But, by specifying the <data> tag, you will only receive broadcast Intents that have data with scheme=file.
The BOOT_COMPLETED Intent doesn't have any data, so your receiver won't get it.
You need to specify 2 separate intent filters, like this:
<receiver android:name="com.abc.testapp.MyReceiver" android:enabled="true">
<intent-filter android:priority="500">
<action android:name= "android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
<intent-filter android:priority="500">
<action android:name="android.intent.action.MEDIA_MOUNTED"/>
<data android:scheme="file" />
</intent-filter>
</receiver>
Related
I've almost made my sms app, only one bug still remains. When phone receives incoming sms it somehow goes to my app and to default one. I thought that problem was in action of intent, but changing it does nothing. The question is - how to intercept incoming sms and forbid default app to do the same?
AndroidManifest:
<manifest package="lexzcq.com.smska"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission
android:name="android.permission.SET_PREFERRED_APPLICATIONS"
tools:ignore="ProtectedPermissions"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<intent-filter android:priority="999">
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.APP_MESSAGING"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<receiver
android:name=".SmsReceiver"
android:permission="android.permission.BROADCAST_SMS"
>
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
<category android:name="android.intent.category.APP_MESSAGING"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
<activity android:name=".ChatWindow">
<intent-filter>
<action android:name="com.lexzcq.com.lexzcq.sms_receive_intent"/>
</intent-filter>
</activity>
<application android:name=".MyApp">
</application>
</application>
</manifest>
SmsReceiver.class
public class SmsReceiver extends BroadcastReceiver {
#Override
public void onReceive (Context context, Intent intent) {
*//here I handle sms from pdus*
Intent broadcastIntent = new Intent ()
.putExtra ("address", address)
.putExtra ("body", body)
.setAction ("com.lexzcq.sms_receive_intent");
*//here I'm writing sms to database*
context.sendBroadcast (broadcastIntent);
abortBroadcast ();
}
}
}
If needed - I can provide broadcast receivers from MainActivity.class
P.S. Most weird part - that when I'm sending sms it somehow saves to default app but I didn't broadcast it with SMS_RECEIVED_ACTION.
Hello fellow programmers,
I cant find a proper way to route my application, I would like one file to decide which activity has to be started
I am building an android application that in general contains:
-2 ways to start up
-3 activity's
The application can be launched by clicking the icon (standard launch)
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
And an activity is started when there is an incoming call
<action android:name="android.intent.action.PHONE_STATE" />
In the first setup there was 2 activity's one to register and one to use the application. In this
setup I added an extra activity to check if a token was present and route to the right activity.
In the setup that I have now, all the actions are in the of a broadcast receiver. I tried implementing the logic of the extra activity.
The problem I am facing is the check of the incoming call, it is always launching the same activity CallHandler,
I think routing the application within a broadcast receiver might be bad practice, but I can not find a better way of routing the application, and the current code does not work.
Your help is very much appreciated, the following pieces of code might help explain my issue:
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<receiver android:name=".RoutingCallReceiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
<activity
android:name=".RegisterActivity"
android:label="#string/app_name"
android:windowSoftInputMode="adjustResize|stateVisible" >
</activity>
<activity
android:name=".CallHandler"
android:label="#string/title_activity_main" >
</activity>
<activity
android:name=".CreateCallActivity"
android:label="#string/title_activity_create_call" >
</activity>
</application>
RoutingCallReceiver:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
public class RoutingCallReceiver extends BroadcastReceiver {
TelephonyManager telephony;
Intent in;
public void onReceive(Context context, Intent intent) {
PrimePhoneStateListener phoneListener = new PrimePhoneStateListener();
telephony = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
if(telephony.getCallState()== 1){
in = new Intent(context, CallHandler.class);
in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(in);
}
else {
TokenIO tokenHandler = new TokenIO();
String token = tokenHandler.getToken(context);
Log.d("AAfter", "Token");
if(token.equals("") || token.equals(null)){
in = new Intent(context, RegisterActivity.class);
in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(in);
}
else{
in = new Intent(context, CreateCallActivity.class);
in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(in);
}
}
}
// when finish your job, stop listen to changes
public void onDestroy() {
telephony.listen(null, PhoneStateListener.LISTEN_NONE);
}
}
you can make change in your xml file
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<receiver android:name=".RoutingCallReceiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
<activity
android:name=".RegisterActivity"
android:label="#string/app_name"
android:windowSoftInputMode="adjustResize|stateVisible" >
</activity>
<activity
android:name=".CallHandler"
android:label="#string/title_activity_main" >
</activity>
<activity
android:name=".CreateCallActivity"
android:label="#string/title_activity_create_call" >
</activity>
</application>
and put this tag into main activity
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
and i hope that will work fine.
I have two launcher activities,
1. Receiver activity which is a Broadcast Receiver.
2. An Activity which should be main Launcher activity.
When an SMS arrives the receiver activity launches the .MainActivity(BroadcastReceiver) and it further start one service. (Without GUI) and without opening Settings activity.
Another activity .Settings is Main launcher activity.
Goal I want to Achive:
When sms arrived receiver activity work as it is. But When I want to change the settings Setting activity starts.
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.aa"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.RECEIVE_SMS" >
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.aa.FindLocation"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.aa.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.aa.Settings"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.aa.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".MainActivity"
android:enabled="false" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
<service android:name=".Servc" >
<intent-filter>
<action android:name="com.example.Servc" />
</intent-filter>
</service>
</application>
</manifest>
Problem
1.
[2014-07-06 02:55:14 - Aa] Uploading Aa.apk onto device 'S5830f4524b76'
[2014-07-06 02:55:14 - Aa] Installing Aa.apk...
[2014-07-06 02:55:18 - Aa] Success!
[2014-07-06 02:55:18 - Aa] Starting activity com.example.aa.Settings on device S5830f4524b76
[2014-07-06 02:55:19 - Aa] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.aa/.Settings }
2.
What changes should be made in manifest to make it working?
Don't define your sms receiver in the manifest. Remove it.
Create Broadcast receiver that runs on boot up by defining the below element in your manifest :
<receiver android:name=".BootUpReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
You will need to add this permission to your manifest :
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
Then register your sms receiving BroadcastReceiver in there :
public class BootUpReceiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
SmsReceiver smsreceiver = new SmsReceiver();
IntentFilter fltr_smsreceived = new IntentFilter(
"android.provider.Telephony.SMS_RECEIVED");
registerReceiver(smsreceiver, fltr_smsreceived);
}
}
SmsReceiver is your broadcast receiver. For example :
public class SmsReceiver extends BroadcastReceiver {
void setActivityHandler(){
//instantiate member variables if required
}
#Override
public void onReceive(Context context, Intent intent) {
Bundle pdusBundle = intent.getExtras();
Object[] pdus=(Object[])pdusBundle.get("pdus");
SmsMessage messages=SmsMessage.createFromPdu((byte[]) pdus[0]);
Log.d("tag","message body : " + messages.getMessageBody());
}
}
I am trying to get my app to auto start on boot up and it will and an error occurs while launching the application
Here is my manifest and the program file for the "Auto Starter":
manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="this.bad.file"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="autoBot"
android:enabled="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
Here is the "AutoBot" as I have called it (Not for spammy reasons I just like transformers):
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class autoBot extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Intent startUp = new Intent(context, MainActivity.class);
context.startActivity(startUp);
}
}
So there we have it!
In your manifest, you left out a vital name of the class, usually, can be abbreviated to [dot][ClassName] or the full package name, as in for example .autoBot or see the example below:
<receiver android:name="this.bad.file.autoBot">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
And in your Broadcast receiver:
public class autoBot extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent startUp = new Intent(context, MainActivity.class);
context.startActivity(startUp);
}
}
Notice the usage of #Override on the onReceive class.
The normal recommended route to take is usually, to start an alarm on boot, and listen for the broadcast when the alarm has expired, in that way your activity does not hog up the boot and also, allow the boot up process to "settle" for a bit.
I am new to android development, and
I have an app that when run from the app icon in the menu / home screens runs just fine. However when I try to make it run on boot completion it crashes (Keeping in mind that if I go back to the Icon it will still work) I am wondering what is wrong here. Keep in mind I am doing testing on my personal phone which is android 2.3 and it is ROOTED. Some how I don't think this should be as hard as it is to do, since 9/10 most android apps work in this way or in a way similar to this. Simply put: What am I doing wrong?
In the mean time here is my code for the Broadcast Receiver:
package path.to.file;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class autoBot extends BroadcastReceiver {
private static final String LOG_TAG = "StartAtBootServiceReceiver";
#Override
public void onReceive(Context context, Intent intent) {
Log.e(LOG_TAG, "onReceive:");
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Intent i = new Intent();
i.setAction("path.to.file.MainActivity");
context.startActivity(i);
}
}
}
As well as the Manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
installlocation="internalOnly"
package="path.to.file"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="autoBot" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" >
</action>
<category android:name="android.intent.category.HOME" >
</category>
</intent-filter>
</receiver>
</application>
</manifest>
Is there a specific reason you are adding an action to your intent? If your only aim is to launch your activity at start-up, do this in your BroadcastReceiver:
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
Also, remove these lines from your manifest under receiver tag, you won't need them there:
<category android:name="android.intent.category.HOME" ></category>