How to disable statusbar in android? - android

i want disable statusbar in activity, i have use below code, it happen SecurityException,
StatusBarManagerService: Neither user 10049 nor current process has android.permission.STATUS_BAR. I have add <uses-permission android:name="android.permission.STATUS_BAR">, but it's not works? Anyone know how to resolve this problem? Thanks
mStatusBar = getSystemService("statusbar");
if (mStatusBar != null){
Log.v("statusbar", "get status bar service "+mStatusBar.getClass());
Method[] arrayOfMethods;
Method localMethod;
arrayOfMethods = mStatusBar.getClass().getMethods();
for (int i = 0; i < arrayOfMethods.length; i++){
localMethod = arrayOfMethods[i];
Log.v("statusbar", "find status bar method "+localMethod);
if (localMethod.getName().equalsIgnoreCase("collapse")){
// mStatusBarCollapseMethod = localMethod;
} else if (localMethod.getName().equals("disable")){
try {
Log.v("statusbar", "invoke "+mStatusBar+"."+localMethod.getName()+"(1)");
localMethod.invoke(mStatusBar, 1);
Log.v("statusbar", "disable statusbar");
} catch (Exception e) {
Log.v("statusbar", "disable statusbar excption:"+e.toString());
e.printStackTrace();
}
}
}
}
}

IF you need to disable the status bar from your java code, then you can do this:
Window win = getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

Simple solution, just add android:theme=”#android:style/Theme.NoTitleBar.Fullscreen” to your manifest, for example:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.vogella.android.temperature"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".Convert"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="9" />
</manifest>

Related

Screen Overlay Detected Android

I found the below issue of Screen Overlay detected when click permission in Motog3 marshmallow mobile.
i found many solution over internet search everywhere, you can check below:
Remove esfile explorer
https://www.youtube.com/watch?v=QHidevTDrYI
Screen overlay detected blocks Android permissions
https://android.stackexchange.com/questions/148260/screen-overlay-detected-what-is-the-problem
https://forums.androidcentral.com/android-6-0-marshmallow/682802-screen-overlay-detected-what-can-i-do.html
https://www.howtogeek.com/271519/how-to-fix-the-screen-overlay-detected-error-on-android/
https://github.com/MohammadAdib/Roundr/issues/10
Android marshmallow : Galaxy Note 4 Screen Overlay Detected
etc. many more.
If i don't call permission below then no problem.
Therefore if anyone want to give the best solution then please share.
Please before mentioning it duplicate, i want proper solution for it.
Feel free to ask any information or code i'm sharing some code also.
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.psm">
<!---->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/logo"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/MyMaterialTheme">
<activity android:name=".MainActivity"
android:screenOrientation="portrait">
</activity>
<activity android:name=".SplashScreen"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.nippon.registration.Registration"
></activity>
</application>
</manifest>
Permission code in Mainactivity.java
checkAndRequestPermissions(); //called in oncreate() of activity
private boolean checkAndRequestPermissions() {
try {
int permissionWriteEXTERNALSTORAGE = ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
int PermissionCamera = ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA);
List<String> listPermissionsNeeded = new ArrayList<>();
if (permissionWriteEXTERNALSTORAGE != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
if (PermissionCamera != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(android.Manifest.permission.CAMERA);
}
if (!listPermissionsNeeded.isEmpty()) {
ActivityCompat.requestPermissions(this, listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]), 1);
return false;
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
Thanks in advance, for perfect solution.
finally i got solution for above problem of Screen Overlay Detected
by removing below code which i was using for testing memory usage in app:
final Runtime runtime = Runtime.getRuntime();
final long usedMemInMB=(runtime.totalMemory() - runtime.freeMemory()) / 1048576L;
final long maxHeapSizeInMB=runtime.maxMemory() / 1048576L;
final long availHeapSizeInMB = maxHeapSizeInMB - usedMemInMB;
Toast.makeText(getApplicationContext(),String.valueOf(usedMemInMB+" "+ maxHeapSizeInMB+" "+ availHeapSizeInMB), Toast.LENGTH_LONG).show();
Thanks for everyone support!

BroadcastReceiver onReceive() not called when Google Glass is connected to Android device

I'm trying to connect Google Glass with an Android device over USB. But when I connect them over USB, the Android device is working fine and its BroadcastReceiver onReceive() run, but on the other hand Google Glass BroadcastReceiver onReceive() method never get called.
The code that works is below:
in onResume() :
registerReceiver(mUsbDeviceReceiver, new intentFilter(UsbManager.ACTION_USB_DEVICE_ATTACHED));
Broadcast:
private final BroadcastReceiver mUsbDeviceReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
// some code...
} else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
// some code...
} else {
// some code...
}
}
};
Below is the Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.usb.glass"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<uses-feature android:name="android.hardware.usb.host" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.usb.glass.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<!-- <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="#xml/device_filter" /> -->
</activity>
</application>
</manifest>
Any help?

App crashes silent: try catch finally does not work

I have a small app where I play with activating an activity by code. There I have the strange problem that my app dies after enabling a second activity.
Here is my settings activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
Log.e(getClass().getSimpleName(), "enableing activity...");
PackageManager pm = getPackageManager();
try {
ComponentName componentName = new ComponentName(this, Lancher.class);
pm.setComponentEnabledSetting(componentName,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0);
} catch(Exception e) {
Log.e(getClass().getSimpleName(), "Got some trouble:", e);
} finally {
Log.e(getClass().getSimpleName(), "reached finally block");
}
Log.e(getClass().getSimpleName(), "wohoo activity is enabled");
// ...
And here are some lines of my logcat (I removed unrelated output):
I/ActivityManager(1384): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.test/.Settings } from pid 6566
...
E/Settings(6592): enableing activity...
I/PackageManager(1384): setEnabledSetting(), pkgName=com.example.test, clsName=com.example.test.Lancher, state=1, flag=0, pid=6592, uid=10203
...
D/WindowManagerImpl(1384): finishRemoveViewLocked, mViews[1]: com.android.internal.policy.impl.PhoneWindow$DecorView#4054d318
D/Process(1384): killProcess, pid=6592
I/ActivityManager(1384): Force stopping package com.example.test uid=10203
I/RegisterService(6601): android.intent.action.PACKAGE_REMOVED package:com.example.test
And my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Settings"
android:label="#string/app_name"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Lancher"
android:enabled="false"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</activity>
</application>
</manifest>
Do you have any idea why my app crashes without any output from the finally block?
It works when you change flag from 0 to 1 or PackageManager.DONT_KILL_APP
pm.setComponentEnabledSetting(componentName,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
Maybe this is an android issue or misunderstanding android docs.
Do you need really need flag == 0?

Translate in Android using Google API

I want to create a translate app in Android,i use Google Translate API,but it has error,please help me for fix it. This is my code
public void onClick(View v) {
// TODO Auto-generated method stub
String InputString;
String OutputString = null;
InputString = InputText.getText().toString();
try {
Translate.setHttpReferrer("http://translate.google.com.vn/");
OutputString = Translate.DEFAULT.execute(InputString, Language.ENGLISH, Language.VIETNAMESE); ////////
} catch (Exception ex) {
ex.printStackTrace();
OutputString = "Error";
}
OutputText.setText(OutputString);
}
Here is my Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.stthing"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<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>
</application>
</manifest>
Error in line Translate.setHttpReferrer("http://translate.google.com.vn/");
The method setHttpReferrer(String) is undefined for the type Translate
I am not sure if you are aware but Translate API is no longer free. so you would need to set the API key as well..
instead of using
Translate.setHttpReferrer("http://translate.google.com.vn/");
use
GoogleAPI.setHttpReferrer("http://translate.google.com.vn/");
GoogleAPI.setKey(/* Enter your API key here */);

IntentService is not being called

I am trying to send an Intent from the onCreate in an Activity to start an IntentService. However the IntentService's onHandleIntent is never being received. I have tried changing around the Manifest with Intent-filters but nothing seems to be working. No exceptions are being thrown, but the IntentService is simply not called.
Here is the onCreate
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
db = new TwitterDB(this);
String[] columns = new String[1];
columns[0] = TwitterDB.TEXT;
tAdapter = new SimpleCursorAdapter(this, 0, null, columns, null, 0);
tweets = (ListView)findViewById(R.id.listtwitter);
tweets.setAdapter(tAdapter);
Intent intent = new Intent(this, SyncService.class);
intent.putExtra("action", SyncService.TWITTER_SYNC);
this.startService(intent);
}
Here is the creator and onHandleIntent of the IntentService class, I know it is not being called because logcat never shows "Retrieved intent". The constructor is not called either (There was a log call in there, but I removed it.
public SyncService(){
super("SyncService");
twitterURI = Uri.parse(TWITTER_URI);
Log.i("SyncService", "Constructed");
}
#Override
public void onHandleIntent(Intent i){
int action = i.getIntExtra("action", -1);
Log.i("SyncService", "Retrieved intent");
switch (action){
case TWITTER_SYNC:
try{
url = new URL(twitterString);
conn = (HttpURLConnection)url.openConnection();
syncTwitterDB();
conn.disconnect();
}catch(MalformedURLException e){
Log.w("SyncService", "Twitter URL is no longer valid.");
e.printStackTrace();
}catch(IOException e){
Log.w("SyncService", "Twitter connection could not be established.");
e.printStackTrace();
}
break;
default:;
// invalid request
}
}
And here is the Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.twitter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<application android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".TwitterTwoActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<service android:name="SyncService"/>
</activity>
</application>
</manifest>
Move your service declaration outside of the scope of the TwitterTwoActivity in the XML file, as I have done here:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.twitter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<application android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".TwitterTwoActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="SyncService"/>
</application>
</manifest>
You need to define the path to the service in your manifest, simply putting the name is not sufficient.
Change
<service android:name="SyncService"/>
to
<service android:name=".SyncService"/>
if SyncService is in the root of your package, add respective folder before .SyncService if needed.

Categories

Resources