how to add myApp to complete action using? - java

when you click on a video android give you some suggestion app to open the video i wnat to add my app to the list. name of the list is complete action using and this doc is related https://developer.android.com/training/basics/intents/filters.html
but i am beginner and dont know how to use the doc for video
<activity android:name="ShareActivity">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
<data android:mimeType="image/*"/>
</intent-filter>
</activity>
and please guide me how to handle the intent in activity

Put this code into your manifest in your activity tag :
<intent-filter tools:ignore="AppLinkUrlError">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="video/*" />
</intent-filter>
It will show your app into a suggestion list whenever user selects a video file from his phone. ALthough, you need to handle the further actions in your videoplayer activity.
Because this tag will only help you getting your into a suggestion list, to play a selected video, you have to use intent to get the selected video uri. You can find the examples of playing a video file like this on the internet easily.

There are two ways I know to achieve this kind of things.
BroadcastReceiver
Manifest.xml
<application
...
<!-- BROADCAST RECEIVER -->
<receiver
android:name="com.package.app.Broadcaster"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
<data android:mimeType="image/*"/>
</intent-filter>
</receiver>
<activity
...
</activity>
...
</application>
com.package.app.Broadcaster
public final class Broadcaster extends BroadcastReceiver
{
#Override
public final void onReceive(final Context context, final Intent intent) {
//Activity to handle the files.
intent.setClass(context, MainActivity.class);
//RuntimeException without this flag.
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
Service
Manifest.xml
<application
...
<!-- SERVICE -->
<service
android:enabled="true"
android:name="com.package.app.Servicer"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
<data android:mimeType="image/*"/>
</intent-filter>
</service>
<activity
...
</activity>
...
</application>
com.package.app.Servicer
public final class Servicer extends Service
{
#Override
public final int onStartCommand(final Intent intent, final int flags, final int startId) {
//Activity to handle the files
intent.setClass(this, MainActivity.class);
//RuntimeException without this flag.
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
//Stop this service.
stopSelfResult(startId);
return super.onStartCommand(intent, flags, startId);
}
#Override
public final IBinder onBind(final Intent intent) {
return null;
}
}

Related

how to programmatically enable Auto-start option for my app in Chinese devices?

how to enable auto start option in my app without user influence? please help me
public class BootUpReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, Splash_Screen.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"
/>
<receiver android:enabled="true" android:name=".BootUpReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>

AlarmManager doesnot work from bootservice receiver

I have made an application that requires alarms to be fired.Alarm Manager works fine when they are scheduled from some activity. Since alarms are deleted when reboot occurs,i have made a boot_Receiver to reschedule the alarms. But the problem is that alarms are not fired when they are scheduled from the bootreceiver class. Please Help..
AlarmManager Class:-
public class NotifyService extends WakefulBroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Notification_Holder notifholder;
Type t=new TypeToken<Notification_Holder>(){}.getType();
Gson js=new Gson();
notifholder=js.fromJson(intent.getStringExtra("one"),t);
Notification_Creator notifcreator=new Notification_Creator(notifholder.title,notifholder.content,notifholder.cal,context);
notifcreator.create_notification();
}
}
BootReceiver class:-
public class AtBoot extends BroadcastReceiver {
SharedPreferences sharedPreferences;
AlarmManager alarmManager;
Intent x;
PendingIntent pendingIntent;
#Override
public void onReceive(Context context, Intent intent) {
sharedPreferences = context.getSharedPreferences("todoshared", Context.MODE_PRIVATE);
String f = sharedPreferences.getString("todolist", null);
Gson json = new Gson();
alarmManager=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
vClass.notes = Notification_Holder.convert_from_jason(f);
x=new Intent(context,NotifyService.class);
pendingIntent=PendingIntent.getService(context,2100,x,0);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),pendingIntent);
Vibrator vib=(Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
if(vib.hasVibrator()) {
vib.vibrate(1500);
}
}
}
Manifest File:-
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:label="#string/app_name"
android:supportsRtl="true"
android:icon="#mipmap/ic_launcher"
android:theme="#style/MyAppBar">
<activity
android:name=".scrapper"
android:noHistory="true"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".schedule"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".workSpace"
android:theme="#style/AppTheme.NoActionBar" />
<receiver android:name=".widget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/widget_info" />
</receiver>
<service
android:name=".widgetService"
android:permission="android.permission.BIND_REMOTEVIEWS" />
<receiver android:name=".NotifyService" />
<activity
android:name=".showSubject"
android:theme="#style/AppTheme.popupTheme" />
<activity android:name=".splashScreen"
android:theme="#style/AppTheme.NoActionBar"
android:noHistory="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".AtBoot"
android:enabled="true"
android:exported="true"
android:label="AtBoot">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
</application>
I have added the vibrator in AtBoot class t check if it is being called on bootup. And the phone vibrates..This means that the class is being invoked on bootup but the alarm part does not work
I think for HTC you should also add in the IntentFilters
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
Also, I think it should be
PendingIntent.getBroadcast(context, 2100, x, 0);
and not
PendingIntent.getService(context,2100,x,0);
The problem was that i was using pendingintent.getService() instead of pendingIntent.getBroadcast() as correctly pointed out by Velislava...

How to create an android app that is set to default when the device is turned on

I want to create an application in android , which after installation I need to set as default when ever the device is turned on .
I have tried the following
created a service ,
created a reciever to recieve boot completion event
It is not working actually.If I remove the launcher for MainActivity the it will show error saying
No Launcher activity found!
The launch will only sync the application package on the device!
my manifest file
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:screenOrientation="sensorLandscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".MyService"
android:label="My Service" >
<intent-filter>
<action android:name="com.example.splash_test.MyService" />
</intent-filter>
</service>
<receiver
android:name=".receiver.MyReceiver"
android:label="MyReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity
android:name="com.example.splash_test.Screen1"
android:label="#string/app_name"
android:screenOrientation="sensorLandscape" >
</activity>
</application>
MyReceiver.java
public class MyReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent serviceIntent = new Intent(context, MyService.class);
context.startService(serviceIntent);
}
}
}
MyService.java
public class MyService extends Service {
#Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Intent i = new Intent(this, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(i);
}
return null;
}
}
You have to follow below steps for achieve this task:-
Make a service in your app(Run all time).
check your app is running or not in service.(Through package name)
if running then good other wise run with the help of service.
Try it.... its working fine in my app. :)

Android Bluetooth - detect a disconnection from a device

I am trying to catch a bluetooth device disconnection intent filter.
I added a log to the onReceive but it never reaches it and is not displayed in the logcat.
I suspect that the problem is with my manifest.xml configuration:
manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.company"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<receiver android:name="com.company.MyReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED" />
<action android:name="android.bluetooth.adapter.action.CONNECTION_STATE_CHANGED" />
<action android:name="android.bluetooth.adapter.action.DISCOVERY_STARTED" />
</intent-filter>
</receiver>
<activity
android:name=".BTActivity"
android:label="BTActivity" >
</activity>
</application>
</manifest>
MyReceiver extends BroadcastReceiver:
#Override
public void onReceive(Context context, Intent intent) {
Log.i("got-in", "got-in-");
// String action = intent.getAction();
BluetoothDevice device = intent
.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
Log.i("disconnect", device.getName());
Intent i = new Intent(context, BTActivity.class);
Bundle b = new Bundle();
b.putString("deviceName", device.getName());
intent.putExtras(b); // Put your id to your next Intent
context.startActivity(i);
// finish();
}
Use this code for receiving a disconnect (when Bluetooth is still turned on):
<intent-filter> <action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" />
</intent-filter>
Also you have to register a service that then registers a broadcast receiver for Bluetooth status change, so your app knows when Bluetooth was turned off and therefore discards all active devices, as you won't receive a ACL_DISCONNECT when Bluetooth is simply turned off.
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
registerReceiver(bluetoothTurnedOnOff, filter);
return START_STICKY;
}
private final BroadcastReceiver bluetoothTurnedOnOff = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_OFF) {
[...]
For new users. it will works . Your manifest file looks
<receiver android:name="(package name).BluetoothReceiver" >
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" />
</intent-filter>
</receiver>
and your receiver will look like
else if (intent.getAction().equals(`enter code here`
BluetoothDevice.ACTION_ACL_DISCONNECTED)) {
// connection lost
Try removing the <category .../> from the intent-filter and try again.
Try android.bluetooth.device.action.ACL_DISCONNECTED action in intent filter. It should solve your problem.

Change page via BroadcastReceiver does not work

I am trying to make a second page show up via a BroadcastReceiver, but the App keeps crashing and I don't know why.
This might be a problem of the correct context.
public class ScreenReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
Log.v("$$$$$", "In Method: ACTION_SCREEN_OFF");
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
Log.v("$$$$$", "In Method: ACTION_SCREEN_ON");
changeActivity(context);
} else if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
Log.v("$$$$$", "In Method: USER_PRESENT");
}
}
public void changeActivity(Context context) {
Intent intent = new Intent(context, Second_Page.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(intent);
}
}
My Manifest. In there I declare the class that the log file states is missing:
<uses-sdk android:minSdkVersion="14" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".CatchUnlockActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="second_page" >
</activity>
</application>
</manifest>
Found the solution:
The declaration of the classes is case-sensitive!
Changed every occurrence from "second_page" to "Second_Page" and now it works.

Categories

Resources