小编And*_*ner的帖子

Android READ PHONE STATE?

我正在尝试创建应用程序READ PHONE STATE以及何时更改手机状态以显示Toast当前状态.但是当我启动它时,应用程序意外停止.

我的课 :

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.widget.TextView;

public class TelephonyDemo extends Activity {
    TextView textOut;
    TelephonyManager telephonyManager;
    PhoneStateListener listener;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Get the UI
        textOut = (TextView) findViewById(R.id.textOut);

        // Get the telephony manager
        telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

        // Create a new PhoneStateListener
        listener = new PhoneStateListener() {
            @Override
            public void …
Run Code Online (Sandbox Code Playgroud)

android android-manifest

15
推荐指数
1
解决办法
9万
查看次数

Android关闭屏幕

我无法使用此代码关闭屏幕.我使用PowerManagerwl.release()方法,但它不起作用.有人能告诉我一个例子吗?

  PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); 
   wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen"); 
Run Code Online (Sandbox Code Playgroud)

这是我的功能的一部分:

  stateString = "nextone";
  if(stateString=="nextone"){        
  wl.release();
   }
Run Code Online (Sandbox Code Playgroud)

我还在清单中添加了权限但没有结果.

android screen

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×2

android-manifest ×1

screen ×1