I'm developing simple webview app and thought of adding some image that works as a button when you click it, it opens share intent.
My app consists of login page activity. After login, it redirects you to webview.
webview.java
This code inside OnCreate
ImageView ShareButton = (ImageView) findViewById(R.id.ShareButton);
ShareButton.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
try {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "URL" );
sendIntent.setType("text/plain");
Intent shareIntent = Intent.createChooser(sendIntent, null);
startActivity(shareIntent);
Toast.makeText(getApplicationContext(), "Button clicked!", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
}
});
layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="center"
android:background="#color/colorPrimary"
tools:context=".LoginActivity">
<WebView
android:id="#+id/webv"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="#+id/ShareButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="11dp"
android:layout_marginTop="11dp"
android:layout_marginBottom="11dp"
android:src="#drawable/ic_add_img" />
</RelativeLayout>
At first install and first run of the webview activity the onclick method works but if i close the app and reopen it again, onclick not working anymore and i have to clear data/cache or reinstall.
What's happening here?
I tried to create separate method outside OnCreate then call it inside OnCreate but it's not working also.
I also tried to set android:onClick="Click" inside image in xml file of webview but errors shows that i should create Click method in login.java instead of webview.java. I created the method there and implemented the code inside a listener but it's not working also.
logs:
I/FIAM.Display: Unbinding from activity: webv
I/FIAM.Headless: Removing display event component
V/FA: Connection attempt already in progress
V/FA: Recording user engagement, ms: 43402
V/FA: Activity paused, time: 414574
D/FA: Connected to remote service
D/FA: Application going to the background
...
I/FIAM.Headless: went foreground
I/FIAM.Display: Binding to activity: webv
I/FIAM.Headless: Setting display event component
I/FIAM.Headless: Forcing fetch from service rather than cache. Test Device: false | App Fresh Install: true
...
V/FA: Activity resumed, time: 534253
V/FA: Connecting to remote service
I/FIAM.Headless: Fetching campaigns from service.
W/DynamiteModule: Local module descriptor class for com.google.android.gms.providerinstaller.dynamite not found.
D/FA: Connected to remote service
I/DynamiteModule: Considering local module
V/FA: Processing queued up service tasks: 1
...
V/NativeCrypto: Read error: ssl=0x756fb141a098: I/O error during system call, Connection reset by peer
V/NativeCrypto: Write error: ssl=0x756fb141a098: I/O error during system call, Broken pipe
D/TrafficStats: tagSocket(201) with statsTag=0xffffffff, statsUid=-1
V/NativeCrypto: SSL shutdown failed: ssl=0x756fb141a098: I/O error during system call, Success
...
I try this code in onCreate and its work fine
ImageView ShareButton = (ImageView) findViewById(R.id.imageView);
ShareButton.setOnClickListener(v -> {
try {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "URL" );
sendIntent.setType("text/plain");
Intent shareIntent = Intent.createChooser(sendIntent, null);
startActivity(shareIntent);
Toast.makeText(getApplicationContext(), "Button clicked!", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
});
Related
I've got a long running application in a kiosk mode, I will call it 'main app'.
Additionally to that, there is another app installed on a device which manages the updates, I will call it 'updater app'. It's a service running in the background + activity which I use for 'debugging' and testing.
Up until android 9, there was no issue with it. The background service would receive info about update, would download it, inform the main app about update ready and when the main app was in a state which would allow an update it would send an intent and start the update.
With Android 9 and 10 things got a bit messy.
I had to add additional permissions, had to add file provider but in the end I got it to work through my 'testing' activity where I push a button and the app will launch download manager and after a successful download, it will launch the installer of the app. Cool.
Unfortunately, this only works when called from the activity of the 'updater'.
If I switch back to my main app and call intent to launch the installation, there is nothing happening - no user prompt whatsoever. I mean: my app sends intent to start the installation and the only thing I can see in logcat is the following warning:
2021-05-28 21:48:33.997 31553-31553/<updater_app> I/Timeline: Timeline: Activity_launch_request time:3253066
2021-05-28 21:48:34.006 1590-1626/? I/ActivityTaskManager: START u0 {act=android.intent.action.VIEW dat=content://<updater_app>.provider/downloads/prod-e470aba2f-6.apk typ=application/vnd.android.package-archive flg=0x10000001 cmp=com.google.android.packageinstaller/com.android.packageinstaller.InstallStart} from uid 10235
2021-05-28 21:48:34.007 1590-1626/? W/ActivityTaskManager: Background activity start [callingPackage: <updater_app>; callingUid: 10235; isCallingUidForeground: false; isCallingUidPersistentSystemProcess: false; realCallingUid: 10235; isRealCallingUidForeground: false; isRealCallingUidPersistentSystemProcess: false; originatingPendingIntent: null; isBgStartWhitelisted: false; intent: Intent { act=android.intent.action.VIEW dat=content://<updater_app>.provider/downloads/prod-e470aba2f-6.apk typ=application/vnd.android.package-archive flg=0x10000001 cmp=com.google.android.packageinstaller/com.android.packageinstaller.InstallStart }; callerApp: ProcessRecord{d1ea9eb 31553:<updater_app>/u0a235}]
I assume there are some more restrictions to take care of, but I don't know where to look for more info. I would be grateful for pointing in the right direction.
I am developing an android application in which I want to display the Push notification.
It has displayed well in most of the devices except Xiaomi phones (I am using Redmi Note 4). The problem that I found is, it is because of Autostart option provided by Xiomi which will be disabled by default and the user need to enable it manually.
But I wonder that some of the Android Apps I could see enabling this option without any user interaction Ex: WhatsApp. If I try reinstalling WhatsApp and see the Autostart option , it is enabled!
I am unable to convince our client by telling it is the feature of Xiomi like devices as he is pointing out some apps which is working fine like the example I have mentioned above.
This question has been asked by some other people
Add my app to AutoStart apps list in android programmatically
How to check AutoStart is enabled for our App in Xiaomi manufacturer mobile device Programmatically
But I could not see any answers for them and Posting here with the hope that someone will have an answer for this.
The autostart feature will get enabled automatically when you will download the app from playstore if xiaomi OS wants it as apps like amazon ,google IO etc are also not allowed to autostart ,In this case you have to go to Security permissions -> autostart -> then enable autostart from there.You cannot make the app autostart by code all you can do is you can show a dialog to enable auto start and take the user to the autostart activity but this is not a good option as you cannot check whether autostart is enabled or not.
This is done by Mi in MIUI8 for saving battery .This issue wasted my 2 days XD
You can refer to this article.
For xiaomi, oppo, vivo, etc. devices to Enable Autostart option programmatically
String manufacturer = android.os.Build.MANUFACTURER;
try {
Intent intent = new Intent();
if ("xiaomi".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
} else if ("oppo".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity"));
} else if ("vivo".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity"));
} else if ("Letv".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.letv.android.letvsafe", "com.letv.android.letvsafe.AutobootManageActivity"));
} else if ("Honor".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
}
List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() > 0) {
startActivity(intent);
}
} catch (Exception e) {
e.printStackTrace();
}
Few popular apps run in background without being killed during memory cleanup cycle (many of the popular OEMs customize the stock ROM for battery/memory optimization), because they are "White listed" by these manufactures.
For your app you can whitelist it either manually (via corresponding "settings" for the devices) or programmatically by redirecting users to the corresponding settings page to white list the app. programmatically you can do like below:
Add below permissions in the App's manifest file:`
<uses-permission android:name="oppo.permission.OPPO_COMPONENT_SAFE"/>
<uses-permission android:name="com.huawei.permission.external_app_settings.USE_COMPONENT"/>`
Redirect your to the Auto Start setting:
if (Build.BRAND.equalsIgnoreCase("xiaomi")) {
Intent intent = new Intent();
intent.setComponent(new
ComponentName("com.miui.securitycenter",
"com.miui.permcenter.autostart.AutoStartManagementActivity"));
startActivity(intent);
} else if (Build.MANUFACTURER.equalsIgnoreCase("oppo")) {
try {
Intent intent = new Intent();
intent.setClassName("com.coloros.safecenter",
"com.coloros.safecenter.permission.startup.StartupAppListActivity");
startActivity(intent);
} catch (Exception e) {
try {
Intent intent = new Intent();
intent.setClassName("com.oppo.safe",
"com.oppo.safe.permission.startup.StartupAppListActivity");
startActivity(intent);
} catch (Exception ex) {
try {
Intent intent = new Intent();
intent.setClassName("com.coloros.safecenter",
"com.coloros.safecenter.startupapp.StartupAppListActivity");
startActivity(intent);
} catch (Exception exx) {
}
}
}
}
AutoStart Reference For other OEMs
I have tested this method and it worked but the reliability is still a question as system taking time (approx 2 Min on PoccoF1 & Xiaomi devices) to restart the killed service.
But as an user we can prevent the app's background services to get killed all together as below :
Press Recent apps physical key (left side button).
Drag down the app once (select, hold & slide it down) tap on the lock icon (if the lock is in open state) to lock the app.
The app will be put in lock condition (even if you clear the background app processes by clearing, the app will keep on running).
Same way, if you want to remove it from the lock condition, just drag down again once and the lock symbol will disappear (clearing the background process will clear the app from running too).
But, With this way App's locking status will be reset on reboot on most of the devices.
EDIT:
After observing the behavior (on Xiaomi's RedmiS3, Android V6.0) of Foreground service here is the analysis:
Even after enabling the "AutoStart" programatically (via user intervention, as explained above) the service didn't restarts always (Service restarted only on few occasions, but most of the time it didn't).
Also, if I search for "AutoStart" in device settings I can't see my app there in the AutoStart list. It seems above method only providing Autostart permission but not enabling it, NOT SURE!.
And, if I add my app into "AutoStart" list via device setting, my service gets restarted (though it takes some time).
Restarting the killed service in onTaskRemoved() callback could be another option but this callback gets called in surprising way when service gets killed. This callback gets executed only when app is been closed properly by back key press. If we minimized the app (Pause state) this callback never gets called on service kill. (Looking for the reason)
Recently I found another way, the killed service could be restarted via GCM notification event. I doubt that weather the GCM works when App's gets killed on the devices or not (I need to check this and verify the behavior). But one this is for sure "These OEMs has made the programmer life hell!).
I know it is too late to share the answer but I will put my two cents here because it is very very important. I wasted my 2 days in digging this problem out. I tried all the suggested solutions as provided here but nothings seemed to be working. Below is the solution I implemented in following steps:
Step # 01
Create your foreground service as you are doing and register it accordingly in manifest. For sample purposes, I am sharing sample of service.
class MyService : Service() {
private var wakeLock: PowerManager.WakeLock? = null
override fun onBind(intent: Intent): IBinder? {
Log.d(tag!!, "Some component want to bind with the service")
// We don't provide binding, so return null
return null
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Log.d(tag!!, "onStartCommand executed with startId: $startId")
// by returning this we make sure the service is restarted if the system kills the service
return START_STICKY
}
override fun onCreate() {
super.onCreate()
Log.d(tag!!, "The service has been created".toUpperCase(Locale.ROOT))
startForeground(1, NotificationUtils.createNotification(this))
acquireLock()
}
override fun onDestroy() {
super.onDestroy()
Log.d(tag!!, "The service has been destroyed".toUpperCase(Locale.ROOT))
Toast.makeText(this, "Service destroyed", Toast.LENGTH_SHORT).show()
}
override fun onTaskRemoved(rootIntent: Intent?) {
Log.d(tag!!, "onTaskRemoved")
val restartServiceIntent = Intent(applicationContext, this.javaClass)
restartServiceIntent.setPackage(packageName)
val restartServicePendingIntent = PendingIntent.getService(applicationContext, 1, restartServiceIntent, PendingIntent.FLAG_ONE_SHOT)
val alarmService = applicationContext.getSystemService(ALARM_SERVICE) as AlarmManager
alarmService[AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 1000] = restartServicePendingIntent
super.onTaskRemoved(rootIntent)
}
#SuppressLint("WakelockTimeout")
private fun acquireLock() {
// we need this lock so our service gets not affected by Doze Mode
wakeLock =
(getSystemService(Context.POWER_SERVICE) as PowerManager).run {
newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyService::lock").apply {
acquire()
}
}
}
}
NOTE: I have covered all the possible use cases to restart the Service in case it gets killed by OS. There is one thing left if user restarts cell phone. This case can be found via other stackoverflow answers very easy. In Broadcast one just needs to start Service.
Step # 02
Make an application and register in manifest. And add below line of code in your application class.
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
val receiver = ComponentName(this, MyService::class.java)
val pm = packageManager
pm.setComponentEnabledSetting(
receiver,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP
)
}
}
Here, MyService is the component name and this can be Service or Broad cast Receiver you are already using in you app. In my case I trie with Android service
Now, this is the time to register this Application class in Manifest file. Open the manifest file and in application tag use property name and place your application class name which was just created MyApplication.
Step # 03
There is no third step. You are done. You just install the apk and by this way Service will not killed even the app is killed. I tested the above solution on Vivo device and it worked
NOTE: In case, above solution does not work, please check the manifest file for allowBackup property if you find out this property in manifest file just remove it and uninstall the app and then install the app it will work for sure and then you can set that property again.
As far as I know, WhatsApp is whitelisted on the Xiaomi device autostart. There is nothing you can do about it. Of course your application will be whitelisted by Xiaomi if it eventually garnered as much as WhatsApp popularity. Until that happens, you can only asking for user to activate it manually by showing the Auto-start feature with something like this:
try {
Intent intent = new Intent();
if ("xiaomi".equalsIgnoreCase(android.os.Build.MANUFACTURER)) {
intent.setComponent(new ComponentName("com.miui.securitycenter",
"com.miui.permcenter.autostart.AutoStartManagementActivity"));
}
// context is your Context
List<ResolveInfo> list = context.getPackageManager()
.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() > 0) {
context.startActivity(intent);
}
} catch (Exception e) {
Log.d("PERMISSION", e.toString());
}
Please note, that I haven't test the code for current Xiaomi device.
I have an app that streams live audio, but also has a webView that allows users to navigate to our website (from within the App).
The live stream will continue to play regardless of whether the app is the active screen or not, which is the desired behaviour (and we have other apps taht do this that have not been rejected).
On one of our apps, the website (via the webView) can access a YouTube video and my understanding is that this particular app has fallen foul of Google Plays 4.4 (Your app is violating our policy because it enables the user to play YouTube content in the background while the app is not active (meaning all playback should stop, once the user closes the app, including pressing the "power" button) because if, for example, you press the power button to turn off the screen, the YouTube video continues to play in the background.
My understanding is that the rejection is due to this behaviour (YouTube video is allowed to continue to play) rather than the app itself continuing to stream the live audio).
On this basis, how could I detect if the power button is pressed, or if the screen sleeps, to switch away from the webView, say, back to the home screen?
From the app launch, you get presented with a menu and can choose the webView from one of the menu buttons, which opens within the App. The desired solution here would be that it the home or power button are pressed (or the devices turns the screen off), the webview would close and return to the main menu.
I'm not necessarily after code (though that would be appreciated!) but I am after advice/confirmation that this is the likely cause of the rejection my idea is the correct one to overcome/comply with the terms set by Google.
Thanks in advance.
UPDATE : I'm using this code in HomeActivity. The VOLUME_UP, VOLUME_DOWN and KEYCODE_BACK all perform as expected, but the KEYCODE_POWER does not, my desired effect is for it to go back (using the onBackPressed();) but it just turns the screen off and the video continues to play in the background
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,
AudioManager.ADJUST_RAISE, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,
AudioManager.ADJUST_LOWER, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
return true;
case KeyEvent.KEYCODE_BACK:
onBackPressed();
return true;
case KeyEvent.KEYCODE_POWER:
onBackPressed();
onPause();
return true;
default:
return false;
}
}
I have also put an Log.i for each button, they all log a key press except the power button. In the log, when I hit power, I get this:
V/FA: Activity paused, time: 1782547095
D/FA: Application backgrounded. Logging engagement
D/FA: Logging event (FE): _e, Bundle[{_o=auto, _et=46202}]
V/FA: Using measurement service
V/FA: Connecting to remote service
D/FA: Connected to remote service
V/FA: Processing queued up service tasks: 1
V/FA: Inactivity, disconnecting from the service
Update:
I put this in the onPause(), which has resolved the issue for me, it is probably a workaround, as what it does is it causes the webview to reload the page, thus stopping the vYouTube video in the webview and the app has actually just been approved BUT, it now crashes on exit with the following, which is a direct result of the code I added (if i take it out, the crash stops):
#Override
protected void onPause() {
Webservice.getInstance().activity = "listen";
WebviewActivity webviewActivity=new WebviewActivity();
Bundle bundle=new Bundle();
bundle.putString("type","web");
bundle.putString("url","http://www.website.com");
webviewActivity.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.container,webviewActivity,"WebviewActivity").commit();
super.onPause();
}
Above it what it has now (stops video, but crashes). It originally had this (didn't stop video, but no crash):
#Override
protected void onPause() {
super.onPause();
Webservice.getInstance().activity = "listen";
}
The crash log is this:
/AndroidRuntime: FATAL EXCEPTION: main
Process: com.auto.packagename, PID: 10484
java.lang.IllegalArgumentException: View=DecorView#169b874[] not attached to window manager
at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:473)
at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:382)
at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:124)
at android.app.Dialog.dismissDialog(Dialog.java:357)
at android.app.Dialog.dismiss(Dialog.java:340)
at com.soft.network.fragments.WebviewActivity$2.onProgressChanged(WebviewActivity.java:67)
at com.android.webview.chromium.Ap.onProgressChanged(WebViewContentsClientAdapter.java:45)
at org.chromium.android_webview.AwContentsClientCallbackHelper$MyHandler.handleMessage(AwContentsClientCallbackHelper.java:79)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:173)
at android.app.ActivityThread.main(ActivityThread.java:6464)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:938)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:828)
D/LOG: Asking for stream handler for protocol: 'https'
D/libc: [NET] android_getaddrinfo_proxy get netid:0
D/libc: [NET] android_getaddrinfo_proxy-, success
I/CrashlyticsCore: Crashlytics report upload complete: 5A68B5D20084-0001-28F4-4DB370E6A585
Application terminated.
Update (inside WebviewActivity.java)
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
if(progress == 100)
progressDialog.dismiss();
}
});
There is also a onProgressChanged in HomeActivity.java, but it is commented out.
Well, you can use these mehtods:
OnBackPressed() if the user pressed back button
OnDestroy() it called before the activity is destroyed
OnStop() the activity is no longer visible
I have two apps that both have kiosk mode enabled. I currently send a broadcast from one to the other that transmits data. I want to tell the receiving app to start a new activity.
In most cases I would be able to use intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); however... I am not able to start a new task while in kiosk mode.
Here is what I have in the broadcastReceiver(which I have verified works for other data). This code tries to start a new activity:
Intent launchIntent = new Intent(Intent.ACTION_MAIN);
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // this doesn't work in kiosk mode...
launchIntent.setComponent(new ComponentName("my.package","my.package.myactivity"));
try {
if(launchIntent != null) {
context.getApplicationContext().startActivity(launchIntent);
Log.i(TAG, "Started activity");
} else
Log.i(TAG, "Intent is null");
} catch (Exception e) {
Log.e(TAG, e.toString());
}
My error before adding the flag:
Kiosk Mode: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
And after adding the flag:
E/ActivityManager( 470): Attempted Lock Task Mode violation
Is it possible to send a context through a broadcast receiver, perhaps, so that I can start the desired activity using that context? Can anyone suggest another method other than using broadcasts to start new activity?
Note: In Android "ScreenPinning", "Kioskmode" and "Lock Task Mode" are the same.
from https://developer.android.com/about/versions/android-5.0.html#ScreenPinning
Once your app activates screen pinning, users cannot (...)
access other apps (...) until your app exits the mode.
You have to temprary disable the kioskmode with stopLockTask() interact and re-enable it with startLockTask()
To prevent android from asking the user to re-start kioskmode you also need to implement a https://developer.android.com/about/versions/android-5.0.html#DeviceOwner app
You can find a lot of infos about this topic at https://github.com/Tuong-Nguyen/Android/wiki/Research-114-Kiosk-Mode-Android-application
package supa.mack.doppler;
import java.util.Set;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.bluetooth.*;
import android.widget.Toast;
public class doppler_test extends Activity {
TextView out;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
out = (TextView) findViewById(R.id.out);
// Getting the Bluetooth adapter
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
out.append("\nAdapter: " + adapter);
// Check for Bluetooth support in the first place
// Emulator doesn't support Bluetooth and will return null
if(adapter==null) {
out.append("\nBluetooth NOT supported. Aborting.");
return;
}
// Starting the device discovery
out.append("\nStarting discovery...");
adapter.startDiscovery();
out.append("\nDone with discovery...");
// Listing paired devices
out.append("\nDevices Pared:");
Set<BluetoothDevice> devices = adapter.getBondedDevices();
for (BluetoothDevice device : devices) {
out.append("\nFound device: " + device);
}
Button searchButton=(Button) findViewById(R.id.search_button);
searchButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Intent intent=new Intent(
doppler_test.this,
search_result.class
);
startActivity(intent);
}
});
}
}
--------------------------------------…
Here is the code where the problem lies....
It doesn't give me an error it says exactly this when I run the android emulator
"[2010-08-25 09:12:42 - doppler_test] ActivityManager: Warning: Activity not started, its current task has been brought to the front"
What I think this means is that the intent of the bluetooth function and the button intent is only operation on a hierarchy system. What I mean by this is that if I were to move the button opperator above the Bluetooth stuff the button will work, but currently when the app is run Bluetooth works but when I press the search button nothing happens.
What else may be helpful is my XML code for the button so here it is......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.co…
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:background="#color/purple_flurp"…
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello"/>
<Button
android:id="#+id/search_button"
android:layout_height="wrap_content"
android:text="#string/search"
android:layout_width="fill_parent"/>
<TextView
android:text="#+id/TextView01"
android:id="#+id/out"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
--------------------------------------…
any ideas?
Anything would be great!
Thanks
Are you getting the warning when you start the app or when you click the button? If you run an app from eclipse without it having to recompile (ie no code changes), it doesn't go through the uninstall-install process, it just pushes the application to the front just like you would if you resumed it from the phone. It's not an error but a 'working as intended'
thats problem is obvious on eclipse with adt plugin. Main problem is ... your application was started on emulator/device and now you try start it again without any changes on source codes.
Possible solutions :
1 rebuild project and start app again (its take more time)
2 add some space/new line to code and start app again
I prefer second options coz its very fast. But IMHO i think its stupid problem on side plugin's developers
In my case the problem was the bad configuration of my HTC connected to PC. Try to run the emulator with the phone disconnected-
It's posible, in case, if yours AVD is started and Locked. You need unlock AVD display.
This means that the app which you try to deply in emulator and already existing same app in emulator are same. There is no change in both of them..
Still you get error then Project -> Clean from eclipse and restart avd and deply again..
If you get this warning it means you haven't changed any line of your code and this instance of your project is running on emulator or on your device. So if you want to run that again you can:
1- Make some changes in your code and then compile it again.
2- Or you can easily close the app and then relaunch it with eclipse or android studio or ...
If the problem still persist try to uninstall the app and run it again.