我想检查用户是启用还是禁用了一个应用程序.
我唯一知道的是我可以得到这个 int
int appstate= this.getPackageManager().getApplicationEnabledSetting("com.example.app");
Run Code Online (Sandbox Code Playgroud)
如何使用此int来检查应用程序是启用还是禁用?
例
if(......){//is enabled
}
else{
//disabled
}
Run Code Online (Sandbox Code Playgroud) 我编辑了build.prop,现在我的手机无法启动.我使用adb拉了build.prop,现在我有了正确的build.prop文件
我需要的是使用adb推送build.prop.
首先尝试:只读文件系统
当我挂载系统时:
第二次尝试:Permision拒绝
我能做什么?
一位用户昨天向我发送了这份崩溃报告:
android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@4250d6d8 is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:698)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:326)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
at android.view.Window$LocalWindowManager.addView(Window.java:552)
at android.app.Dialog.show(Dialog.java:277)
at android.app.AlertDialog$Builder.show(AlertDialog.java:932)
at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:833)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
所以我搜索了,据说解决方案是this
改为Activity.this
但是即使我使用以下代码,这个解决方案也没有用:
//Oncreate Method.....
button.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
AlertDialog.Builder alertd = new AlertDialog.Builder(MainActivity.this);
alertd.setMessage("StackOverflow");
alertd.setTitle("Example");
AlertDialog alertd2 = alertd.create();
alertd2.show();
}
});
Run Code Online (Sandbox Code Playgroud)
我应该改变什么吗?
我正在使用下载管理器,我想使用自己的webview下载一些音频文件.
我使用以下代码:
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url2));
request.setDescription("Downloading");
request.setTitle("File :");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "audio.mp3");
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
Run Code Online (Sandbox Code Playgroud)
即使文件名是audio.mp3,下载管理器也不会识别文件类型.ScreenShot解释了主要问题.
使用默认浏览器下载文件等其他应用程序就像这样!
我想使用自己的webview下载一些文件,但是当我使用下载管理器时,我无法在下载之前获取文件的默认名称.
我试过这个,但它不起作用
String fileName = url.substring(url.lastIndexOf('/') + 1);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName );
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
你需要什么:
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url2) {
if(url2.startsWith("http://www.youtube-mp3.org/get?ab=")){
if(isDownloadManagerAvailable(MainActivity.this)){
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url2));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setMimeType("audio/MP3");
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
//Get file name as string
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, -----);//put it here
manager.enqueue(request);
}
}
else{
view.loadUrl(url2);
}
return false;
}
Run Code Online (Sandbox Code Playgroud)